[WordPress] 外掛分享: Documents from Git

首頁外掛目錄 › Documents from Git
WordPress 外掛 Documents from Git 的封面圖片
200+
安裝啟用
★★★★★
5/5 分(3 則評價)
1621 天前
最後更新
問題解決
WordPress 5.0.0+ PHP 7.0+ v2.2.0 上架:2020-04-02

內容簡介

官方文件: https://github.com/gis-ops/wordpress-markdown-git

這個WordPress外掛讓您能夠輕鬆地從您最喜愛的遠端Git平台上發布、協作和版本控制您的[Markdown, Jupyter notebook]文檔,即使它是自己託管的。

優勢包括:

使用您喜愛的編輯器撰寫文檔,只需將其推送到您的遠端存儲庫即可立即更新您的博客
利用版本控制的威力:在不同的文章中發布不同版本的文檔,例如從除了最新的master之外的另一個分支或提交中發布
簡便地由您的讀者透過pull請求更新文檔,減少過時教程的機會

目前支援以下類型的文檔:

Markdown
Jupyter筆記本(僅限公共存儲庫)

目前支援以下平台:

Github
Bitbucket
Gitlab

使用方法

請注意,這個外掛使用Github精彩的/markdown API來呈現HTML。此處有2個注意事項:

除非授權,否則速率限制被設置為60個請求每分鐘。自v1.1.0版本以來,插件能夠靜態地緩存內容。如果這對您來說不夠靈活,您目前唯一的選擇是不使用任何快取,在這種情況下,每當有人在您的站點上打開文章時,每個文檔都會從您的提供者中拉取。然後強烈建議您創建一個Githu訪問令牌並在外掛中註冊它。然後速率限制將設置為每小時5000個請求。詳細信息請參閱全局屬性部分。
Markdown內容不可以超過400 KB,因此大約是400,000個字符包括空格。如果不是專業論文,這不應該是一個應用限制。

短代碼

本插件具有多種短代碼。

發布文檔

特定於文件的短代碼遵循一種模式[git-do平台-操作],其中

平台可以是以下之一

github:如果您使用Github作為您的版本控制系統平台
bitbucket:如果您使用Bitbucket作為您的版本控制系統平台
gitlab:如果您使用Gitlab作為您的版本控制系統平台

操作可以是以下之一

markdown:以Github的呈現樣式呈現在您的VCS平台上托管的Markdown文件
jupyter:呈現在您的VCS平台上托管的Jupyter筆記本(僅限公共存儲庫)
checkout:呈現一個像徽章一樣的小框,帶有文檔的鏈接和最後一次提交的日期
history:呈現一個包含最後的提交日期、消息和作者的<h2>部分

修改呈現樣式

此外,還有一個包含的短代碼[git-add-css],它添加了一個<div id="git-add-css" class="<classes_attribute>",用於包裹其內容。這樣您可以使用其他CSS類輕鬆地自由操縱樣式。請按照以下步驟進行:

將CSS文件添加到您的主題根目錄中,其中包含一些類,例如class1、class2、class3
通過添加wp_enqueue_style('my-style', get_template_di

外掛標籤

開發者團隊

⬇ 下載最新版 (v2.2.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Documents from Git」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

Official documentation: https://github.com/gis-ops/wordpress-markdown-git
This WordPress Plugin lets you easily publish, collaborate on and version control your [Markdown, Jupyter notebook] documents directly from your favorite remote Git platform, even if it’s self-hosted.
The advantages are:

Write documents in your favorite editor and just push to your remote repository to update your blog instantly
Use the power of version control: publish different versions of the document in different posts, i.e. from another branch or commit than latest master
Easy to update by your readers via pull requests, minimizing the chance of stale tutorials

The following document types are currently supported:

Markdown
Jupyter notebooks (only for public repositories)

The following platforms are currently supported:

Github
Bitbucket
Gitlab

Usage
Note, this plugin uses Github’s wonderful /markdown API to render to HTML. This comes with 2 caveats:

Unless authenticated, the rate limit is set at 60 requests per minute. Since v1.1.0 the plugin is capable of statically caching content. In case that’s not dynamic enough for you, your only option currently is to not use any cache in which case every document will be pulled from your provider every time someone opens it on your site. Then it’s strongly recommended to create a Github access token and register it with the plugin. Then the rate limit will be set to 5000 requests per hour. See Global attributes section for details on how to do that.
The Markdown content cannot exceed 400 KB, so roughly 400 000 characters incl whitespace. If not a monographic dissertation, this should not be an applicable limit though.

Shortcodes
The plugin features a variety of shortcodes.
Publish documents
The document-specific shortcodes follow a pattern of [git--], where

can be one of

github: if you use Github as your VCS platform
bitbucket: if you use Bitbucket as your VCS platform
gitlab: if you use Gitlab as your VCS platform

can be one of

markdown: Render your Markdown files hosted on your VCS platform in Github’s rendering style
jupyter: Render your Jupyter notebook hosted on your VCS platfrom (only for public repositories)
checkout: Renders a small badge-like box with a link to the document and the date of the last commit
history: Renders a

section with the last commit dates, messages and authors

Manipulate rendering style
Additionally, there’s an enclosing shortcode [git-add-css] which adds a

Add a CSS file to your theme’s root folder, which contains some classes, e.g. class1, class2, class3
Enqueue the CSS file by adding wp_enqueue_style('my-style', get_template_directory_uri().'/my-style.css'); to the theme’s functions.php

Add the enclosing git-add-css shortcode to your post with the custom CSS classes in the classes attribute, e.g.:
[git-add-css classes="class1 class2 class3"]
[git-gitlab-checkout url=...]
[git-gitlab-markdown url=...]
[git-gitlab-history url=...]
[/git-add-css]

Attributes
Each shortcode takes a few attributes, indicating if it’s required for public or private repositories:
Attribute
Action
Public repo
Private repo
Type
Description
url
all except git-add-css
:ballot_box_with_check:
:ballot_box_with_check:
string
The browser URL of the document, e.g. https://github.com/gis-ops/wordpress-markdown-git/blob/master/README.md
user
all except git-add-css
:negative_squared_cross_mark:
:ballot_box_with_check:
string
The user name (not email) of an authorized user
token
all except git-add-css
:negative_squared_cross_mark:
:ballot_box_with_check:
string
The access token/app password for the authorized user
cache_ttl
all except git-add-css
:negative_squared_cross_mark:
:negative_squared_cross_mark:
integer
The time in seconds that the plugin will cache, only for cache_strategy=static.
cache_strategy
all except git-add-css
:negative_squared_cross_mark:
:negative_squared_cross_mark:
integer
Only static caching is implemented so far. dynamic caching is on the way!
limit
history
:negative_squared_cross_mark:
:negative_squared_cross_mark:
integer
Limits the history of commits to this number. Default 5.
classes
git-add-css
:ballot_box_with_check:
:ballot_box_with_check:
string
The additional CSS classes to render the content with
Global attributes
Since most attributes will be the same across the entire system, this plugin offers the possibility to set all attributes globally except for url:
In the menu Plugins ► Plugin Editor, choose “Documents from Git” and enter your preferences in the includes/config.json.
Note, setting the attributes manually in the shortcode has always precedence over any settings in includes/config.json.
Caching
Often we need to prioritize speed when loading content and, in addition, it is very costly to fetch, load and format the content every time we need to read the content of the post.
This plugin soon offers 2 methods for caching, static and dynamic which can be set via the cache_strategy property.
Static caching (cache_strategy=static)
This is the default strategy, as it doesn’t require any user action.
The property cache_ttl sets how many seconds the content cache will keep alive.
Currently there’s no way to flush the cache manually. However, changing cache_ttl or the history limit will create a new cache.
Dynamic caching (cache_strategy=dynamic)
This is not implemented yet. See #20 for details.
Token authorization
You need to authorize via user and token if you intend to publish from a private repository. You don’t need to authorize if the repository is open.
However, keep in mind that some platforms have stricter API limits for anonymous requests which are greatly extended if you provide your credentials. So even for public repos it could make sense. And unless you use this plugin’s caching capabilities, it’s strongly recommended to register a Github access token regardless of the VCS hosting platform, see the beginning of the chapter.
How to generate the token depends on your platform:

Github: Generate a Personal Access Token following these instructions
Bitbucket: Generate a App Password following these instructions
Gitlab: Generate a Personal Access Token following these instructions

This plugin needs only Read access to your repositories. Keep that in mind when creating an access token.
Examples
We publish our own tutorials with this plugin: https://gis-ops.com/tutorials/.
Publish Markdown from Github
[git-github-markdown url="https://github.com/gis-ops/tutorials/blob/master/qgis/QGIS_SimplePlugin.md"]

Publish Markdown from Github with 1 hour cache
[git-github-markdown url="https://github.com/gis-ops/tutorials/blob/master/qgis/QGIS_SimplePlugin.md" cache_ttl="3600" cache_strategy="static"]

Publish Jupyter notebook from Github
[git-github-jupyter url="https://github.com/GIScience/openrouteservice-examples/blob/master/python/ortools_pubcrawl.ipynb"]

Publish from a private repository
[git-bitbucket-jupyter user=nilsnolde token=3292_2p3a_84-2af url="https://bitbucket.org/nilsnolde/test-wp-plugin/src/master/README.md"]

Display last commit and document URL from Bitbucket
[git-bitbucket-checkout url="https://bitbucket.org/nilsnolde/test-wp-plugin/src/master/README.md"]

Display commit history from Gitlab
git-gitlab-history limit=5 url="https://gitlab.com/nilsnolde/esy-osm-pbf/-/blob/master/README.md"]

Use additional CSS classes to style
The following example will put a dashed box around the whole post:
`

[git-add-css classes=”md-dashedbox”]
[git-github-checkout url=”https://github.com/gis-ops/tutorials/blob/master/qgis/QGIS_SimplePlugin.md”]
[git-github-markdown url=”https://github.com/gis-ops/tutorials/blob/master/qgis/QGIS_SimplePlugin.md”]
[git-github-history url=”https://github.com/gis-ops/tutorials/blob/master/qgis/QGIS_SimplePlugin.md”]
[/git-add-css]
`
With the following CSS file contents enqueued to your theme:
`css

div.md_dashedbox {
position: relative;
font-size: 0.75em;
border: 3px dashed;
padding: 10px;
margin-bottom:15px
}
div.md_dashedbox div.markdown-github {
color:white;
line-height: 20px;
padding: 0px 5px;
position: absolute;
background-color: #345;
top: -3px;
left: -3px;
text-transform:none;
font-size:1em;
font-family: “Helvetica Neue”,Helvetica,Arial,sans-serif;
}
`

延伸相關外掛

文章
Filter
Apply Filters
Mastodon