Plugin Directory

Changeset 2319715


Ignore:
Timestamp:
06/07/2020 07:52:48 AM (6 years ago)
Author:
nilsnolde
Message:

added authentication to Github's /markdown requests; fixed Jupyter implementation

Location:
documents-from-git/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • documents-from-git/trunk/documents-git.php

    r2274818 r2319715  
    44 * Plugin URI: https://github.com/gis-ops/wordpress-markdown-git
    55 * Description: Render 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.0.1
     6 * Version:     1.0.2
    77 * Author:      GIS-OPS UG
    88 * Author URI:  https://gis-ops.com
  • documents-from-git/trunk/includes/providers/class-base-loader.php

    r2274745 r2319715  
    11<?php
    2 
    3 include_once('../../documents-git.php');
    42
    53abstract class BaseLoader {
     
    7876    public function doJupyter($sc_attrs)
    7977    {
     78        $input_url = $this->extract_attributes($sc_attrs);
     79        $this->set_repo_details($input_url);
     80
    8081        $get_url = $this->get_nbviewer_url();
    8182
     
    131132            case 401:
    132133                $raw_markdown = "# 401 - Bad credentials.\nPlease review access token for user " . $this->user;
     134                break;
     135            case 403:
     136                $raw_markdown = "# 403 - Bad credentials.\nPlease review access token for user " . $this->user;
    133137                break;
    134138            default:
     
    144148            )
    145149        );
     150
     151        // Add the Github credentials to have high /markdown rate limits
     152        $GITHUB_USER = MARKDOWNGIT_CONFIG['Github']['user'];
     153        $GITHUB_TOKEN = MARKDOWNGIT_CONFIG['Github']['token'];
     154        if (!empty($GITHUB_USER) or !empty($GITHUB_TOKEN)) {
     155            $args['headers']['Authorization'] = 'Basic ' . base64_encode($GITHUB_USER . ':' . $GITHUB_TOKEN);
     156        }
     157
    146158        $response = wp_remote_post(self::$GITHUB_MARKDOWN_API, $args);
    147159        $html_body = wp_remote_retrieve_body($response);
  • documents-from-git/trunk/readme.txt

    r2274818 r2319715  
    77Author: GIS-OPS UG
    88Requires at least: 5.0.0
    9 Tested up to: 5.3.2
     9Tested up to: 5.4.1
    1010Requires PHP: 7.0
    11 Stable tag: 1.0.1
    12 Version: 1.0.1
     11Stable tag: 1.0.2
     12Version: 1.0.2
    1313License: GPLv3
    1414License URI: https://github.com/gis-ops/wordpress-markdown-git/blob/master/LICENSE
    1515
    16 A plugin to inject files directly into a post from popular Git platforms.
    17 
    18 Currently supported file types: Markdown.
    19 
    20 Currently supported platforms: Github, Bitbucket.
     16A plugin to inject and render files in a WordPress post or page directly from most popular Git platforms.
     17
     18Currently supported file types: Markdown, Jupyter notebook.
     19
     20Currently supported platforms: Github, Bitbucket, Gitlab.
    2121
    2222== Description ==
     23
     24Official documentation: https://github.com/gis-ops/wordpress-markdown-git
    2325
    2426This 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**.
     
    2830- Write documents in your favorite editor and just push to your remote repository to update your blog instantly
    2931- 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`
    30 - Easy to update by external users via pull requests, minimizes the chance of stale tutorials
     32- Easy to update by your readers via pull requests, minimizing the chance of stale tutorials
    3133
    3234The following document types are currently supported:
     
    4244
    4345## Usage
     46
     47**Note**, this plugin uses Github's wonderful [`/markdown` API](https://developer.github.com/v3/markdown/) to render to HTML. This comes with 2 caveats:
     48
     491. Unless authenticated, the rate limit is set at 60 requests per minute. 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.
     502. 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.
    4451
    4552### Shortcodes
     
    101108You **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.
    102109
    103 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.
     110However, 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 it's strongly recommended to register a Github access token regardless of the VCS hosting platform, see the [beginning of the chapter](#usage).
    104111
    105112How to generate the `token` depends on your platform:
     
    172179```
    173180
     181== Frequently Asked Questions ==
     182
     183= Are relative links supported? =
     184
     185No, relative image links (e.g. `![img](./img.png)`) cannot be processed by this plugin. Please see the notes in the [documentation](https://github.com/gis-ops/wordpress-markdown-git#images) for ways to work around this limitation.
     186
     187= Can I host the source file in a private repository? =
     188
     189Yes, you can, if you provide the plugin's `config.json` with the necessary credentials for your platform (see [documentation](https://github.com/gis-ops/wordpress-markdown-git#global-attributes) for details). However, be aware that all image URLs you are referencing are openly accessible or provide the necessary authentication means. Also see [#13](https://github.com/gis-ops/wordpress-markdown-git/issues/13#issuecomment-638965192) and the [documentation](https://github.com/gis-ops/wordpress-markdown-git#images) for further details.
     190
    174191== Installation ==
    1751921. Install WP Pusher (https://wppusher.com) via ZIP and activate
     
    179196Or directly from WordPress plugin repository.
    180197
    181 Or install as ZIP from https://github.com/gis-ops/wordpress-markdown-git/archive/master.zip
     198Or install the latest code as ZIP from https://github.com/gis-ops/wordpress-markdown-git/archive/master.zip
    182199
    183200== Changelog ==
     201
     202= v1.0.2 =
     203* Fixed rate limiting for unauthenticated `/markdown` requests
     204* Fixed Jupyter implementation
     205
    184206= v1.0.0 =
    185207* First version
Note: See TracChangeset for help on using the changeset viewer.