Skip to content

Commit 7d5954d

Browse files
committedMay 20, 2021
add settings UI replacing the config.json
1 parent eb8074c commit 7d5954d

9 files changed

+1070
-49
lines changed
 

‎CHANGELOG

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
### Removed
1616

17+
## [2.0.0]
18+
19+
### Added
20+
21+
### Fixed
22+
23+
### Changed
24+
25+
- created Settings subpage for the plugin [#5](https://github.com/gis-ops/wordpress-markdown-git/issues/5)
26+
27+
### Removed
28+
29+
## [1.1.1]
30+
31+
### Fixed
32+
33+
- fix Gitlab URLs for subdirectory markdown paths
34+
1735
## [1.1.0]
1836

1937
### Added

‎README.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ The following platforms are currently supported:
2626
1. Unless authenticated, the rate limit is set at 60 requests per minute. Since v1.1.0 the plugin is capable of statically [caching content](#caching). 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](#global-attributes) for details on how to do that.
2727
2. 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.
2828

29+
### Configuration
30+
31+
In the main menu _Settings__Documents from Git_ you can set all important global settings.
32+
33+
**Note**, previous versions used to include a `config.json`. This is **deprecated** now due to security concerns.
34+
2935
### Shortcodes
3036

3137
The plugin features a variety of shortcodes.
@@ -74,14 +80,6 @@ Each shortcode takes a few attributes, indicating if it's required for public or
7480
| `limit` | `history` | :negative_squared_cross_mark: | :negative_squared_cross_mark: | integer | Limits the history of commits to this number. Default 5. |
7581
| `classes` | `git-add-css` | :ballot_box_with_check: | :ballot_box_with_check: | string | The additional CSS classes to render the content with |
7682

77-
#### Global attributes
78-
79-
Since most attributes will be the same across the entire system, this plugin offers the possibility to set all attributes globally except for `url`:
80-
81-
In the menu *Plugins**Plugin Editor*, choose "Documents from Git" and enter your preferences in the `includes/config.json`.
82-
83-
**Note**, setting the attributes manually in the shortcode has always precedence over any settings in `includes/config.json`.
84-
8583
#### Caching
8684

8785
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.

‎documents-git/documents-git.php

+104-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/**
33
* Plugin Name: Documents from Git
44
* Plugin URI: https://github.com/gis-ops/wordpress-markdown-git
5-
* Description: Render and cache various document formats in any post/page directly from a remote Git repository of your favorite platform via shortcodes. Currently supported: Markdown, Jupyter Notebooks.
6-
* Version: 1.1.0
5+
* Description: Render and cache various document formats in any post or page directly from a remote Git repository of your favorite platform via shortcodes. Currently supported: Markdown, Jupyter Notebooks.
6+
* Version: 2.0.0
77
* Author: GIS-OPS UG
88
* Author URI: https://gis-ops.com
99
* Text Domain: documents-git
@@ -15,13 +15,12 @@
1515
exit; // Exit if accessed directly
1616
}
1717

18-
include('includes/providers/class-base-loader.php');
18+
require('includes/providers/class-base-loader.php');
1919

2020
# Add any additional providers here
2121
$providers = ['github', 'bitbucket', 'gitlab'];
2222

2323
define('MARKDOWNGIT_PLUGIN_PATH', dirname( __FILE__ ));
24-
define("MARKDOWNGIT_CONFIG", json_decode(file_get_contents(MARKDOWNGIT_PLUGIN_PATH . '/includes/config.json'), True));
2524

2625
# Add shortcodes for registered providers automatically from $providers
2726
foreach($providers as $provider) {
@@ -38,7 +37,7 @@ function add_enclosing_classes($sc_attrs, $content) {
3837
'classes' => '',
3938
], $sc_attrs));
4039

41-
$classes = ($classes === '') ? (MARKDOWNGIT_CONFIG["classes"]) : ($classes);
40+
$classes = ($classes === '') ? (get_option("git_general", array())['classes']) : ($classes);
4241

4342
$new_content = '';
4443
$new_content .= '<div id="git-add-css" class="' . $classes . '">';
@@ -49,6 +48,103 @@ function add_enclosing_classes($sc_attrs, $content) {
4948
}
5049

5150
# Enqueue Github, nbconvert and plugin stylesheet
52-
add_action('wp_enqueue_style', wp_enqueue_style( 'markdown_git', plugins_url( 'css/markdown-git.css', __FILE__ )));
53-
add_action('wp_enqueue_style', wp_enqueue_style( 'github_markdown', plugins_url( 'css/github-markdown.css', __FILE__ ), 'markdown-git'));
54-
add_action('wp_enqueue_style', wp_enqueue_style( 'nbconvert_git', plugins_url( 'css/nbconvert.css', __FILE__ ), 'markdown-git'));
51+
add_action('wp_enqueue_style', 'add_styles');
52+
function add_styles() {
53+
wp_enqueue_style( 'markdown_git', plugins_url( 'css/markdown-git.css', __FILE__ ));
54+
wp_enqueue_style( 'github_markdown', plugins_url( 'css/github-markdown.css', __FILE__ ));
55+
wp_enqueue_style( 'nbconvert_git', plugins_url( 'css/nbconvert.css', __FILE__ ), 'markdown-git');
56+
}
57+
58+
# Add and set up the Page Builder class
59+
require_once(MARKDOWNGIT_PLUGIN_PATH . '/includes/RationalOptionPages.php');
60+
$pages = array(
61+
'settings_markdowngit' => array(
62+
'parent_slug' => 'options-general.php',
63+
'page_title' => __( 'Settings - Documents from Git', 'documents-from-git' ),
64+
'menu_title' => __( 'Documents from Git', 'documents-from-git' ),
65+
'sections' => array(
66+
'git_general' => array(
67+
'title' => __( 'General Settings', 'documents-from-git' ),
68+
'text' => __( 'Find the official documentation on <a href="https://github.com/gis-ops/wordpress-markdown-git" target="_blank">Github</a>. Contact us on <a href="mailto:enquiry@gis-ops.com">enquiry@gis-ops.com</a>.', 'documents-from-git' ),
69+
'fields' => array(
70+
'limit' => array(
71+
'title' => __( 'History Limit', 'documents-from-git' ),
72+
'id' => 'limit',
73+
'type' => 'number',
74+
'text' => __( 'Set the number of commit messages shown with the <code>git-xxx-history</code> shortcode(s).', 'documents-from-git' ),
75+
'value' => 5,
76+
'attributes' => array(
77+
'required' => true
78+
)
79+
),
80+
'classes' => array(
81+
'title' => __( 'CSS classes', 'documents-from-git' ),
82+
'id' => 'classes',
83+
'text' => __( 'Set (optional) CSS class names which can be wrapped with the <code>git-add-css</code> shortcode, see the <a href="https://github.com/gis-ops/wordpress-markdown-git#use-additional-css-classes-to-style" target="_blank">documentation</a> for usage examples.', 'documents-from-git' ),
84+
'placeholder' => 'my-css-class'
85+
),
86+
'cache_ttl' => array(
87+
'title' => __( 'Cache TTL', 'documents-from-git' ),
88+
'id' => 'cache_ttl',
89+
'type' => 'number',
90+
'text' => __( 'The Time To Live (TTL) for cached documents, <b>in seconds</b>. Defaults to 1 week. To manually flush the case, see the <a href="https://github.com/gis-ops/wordpress-markdown-git#static-caching-cache_strategystatic" target="_blank">documentation</a>.', 'documents-from-git' ),
91+
'value' => 604800,
92+
'attributes' => array(
93+
'required' => true
94+
)
95+
),
96+
)
97+
),
98+
'git_github' => array(
99+
'title' => __( 'Github', 'documents-from-git' ),
100+
'text' => __( 'Regardless if you host any documents on Github, it\'s wise to provide the credentials. The plugin will render Markdown documents via Github\'s <code>/markdown</code> endpoint.', 'documents-from-git' ),
101+
'fields' => array(
102+
'user' => array(
103+
'title' => __( 'Github User', 'documents-from-git' ),
104+
'id' => 'github_user',
105+
'text' => __( 'Your Github <b>user name</b>', 'documents-from-git' )
106+
),
107+
'secret' => array(
108+
'title' => __( 'Github Token', 'documents-from-git' ),
109+
'id' => 'github_secret',
110+
'type' => 'password',
111+
'text' => __( 'The Github <a href="https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token" target="_blank">access token</a>. Needs only <code>repo</code> access.', 'documents-from-git' ),
112+
)
113+
)
114+
),
115+
'git_gitlab' => array(
116+
'title' => __( 'Gitlab', 'documents-from-git' ),
117+
'fields' => array(
118+
'user' => array(
119+
'title' => __( 'Gitlab User', 'documents-from-git' ),
120+
'id' => 'gitlab_user',
121+
'text' => __( 'Your Gitlab <b>user name</b>', 'documents-from-git' )
122+
),
123+
'secret' => array(
124+
'title' => __( 'Gitlab Token', 'documents-from-git' ),
125+
'id' => 'gitlab_secret',
126+
'type' => 'password',
127+
'text' => __( 'The Gitlab <a href="https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#creating-a-personal-access-token" target="_blank">access token</a>. Needs only <code>repo</code> access.', 'documents-from-git' ),
128+
)
129+
)
130+
),
131+
'git_bitbucket' => array(
132+
'title' => __( 'BitBucket', 'documents-from-git' ),
133+
'fields' => array(
134+
'user' => array(
135+
'title' => __( 'BitBucket User', 'documents-from-git' ),
136+
'id' => 'bitbucket_user',
137+
'text' => __( 'Your BitBucket <b>user name</b>', 'documents-from-git' )
138+
),
139+
'secret' => array(
140+
'title' => __( 'BitBucket Token', 'documents-from-git' ),
141+
'id' => 'bitbucket_secret',
142+
'type' => 'password',
143+
'text' => __( 'The BitBucket <a href="https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/#Apppasswords-Createanapppassword" target="_blank">access token</a>. Needs only <code>repo</code> access.', 'documents-from-git' ),
144+
)
145+
)
146+
)
147+
)
148+
)
149+
);
150+
$option_page = new RationalOptionPages( $pages );

0 commit comments

Comments
 (0)