Skip to content

Commit

Permalink
v1.2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vaakash committed Aug 23, 2020
1 parent 0f5c0fe commit 7d79615
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 28 deletions.
7 changes: 6 additions & 1 deletion admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function manage_repo(){
echo '<h2>Configured repositories</h2>';

if( empty( $all_repos ) || count( $all_repos ) == 1 ){
echo '<p class="description">No repositories configured. Go ahead and add one !</p>';
echo '<p class="description">No repositories configured. Go ahead and add one ! See <a href="https://www.aakashweb.com/docs/git-it-write/" target="_blank">getting started</a> for more information.</p>';
}else{

echo '<table class="wp-list-table widefat fixed striped">';
Expand Down Expand Up @@ -455,8 +455,13 @@ public static function sidebar(){
echo '<h2><span class="dashicons dashicons-sos"></span> Help &amp; Support</h2>';
echo '<p>Got any issue or not sure how to achieve what you are looking for with the plugin or have any idea or missing feature ? Let me know. Please post a topic in the forum for an answer.</p>';
echo '<a class="cta_link" href="https://www.aakashweb.com/forum/discuss/wordpress-plugins/git-it-write/" target="_blank">Visit the support forum <span class="dashicons dashicons-arrow-right-alt"></span></a>';
echo '<a class="cta_link" href="https://www.aakashweb.com/docs/git-it-write/" target="_blank">See plugin documentation <span class="dashicons dashicons-arrow-right-alt"></span></a>';
echo '</div>';

echo '<p><a href="https:/vaakash/git-it-write" class="button side_btn" target="_blank"><span class="dashicons dashicons-editor-code"></span> Contribute on Github</a></p>';

echo '<p><a href="https://twitter.com/intent/tweet?hashtags=wordpress,markdown,github&related=aakashweb&text=Check%20it%20out%20-%20%22Git%20it%20Write%22%20a%20new%20WordPress%20plugin%20to%20publish%20posts%20from%20Github%20using%20markdown%20files%20and%20allow%20people%20to%20collaborate%20%E2%9C%8D%20https://wordpress.org/plugins/git-it-write/" class="button side_btn" target="_blank"><span class="dashicons dashicons-share"></span> Share with friends</a></p>';

}

public static function toolbar_extra(){
Expand Down
4 changes: 4 additions & 0 deletions admin/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ table.widefat td {
.side_banner:hover img{
opacity: 0.8;
}
#sidebar .side_btn{
width: 100%;
text-align: center;
}

/* Subscribe form */
.subscribe_form {
Expand Down
4 changes: 2 additions & 2 deletions git-it-write.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
Description: Publish markdown files present in a Github repository as posts to WordPress automatically
Author: Aakash Chakravarthy
Author URI: https://www.aakashweb.com/
Version: 1.1
Version: 1.2
*/

define( 'GIW_VERSION', '1.1' );
define( 'GIW_VERSION', '1.2' );
define( 'GIW_PATH', plugin_dir_path( __FILE__ ) ); // All have trailing slash
define( 'GIW_ADMIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) . 'admin' ) );

Expand Down
3 changes: 2 additions & 1 deletion includes/parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class GIW_Parsedown extends ParsedownExtra{
'menu_order' => 0,
'post_status' => 'publish',
'post_excerpt' => '',
'taxonomy' => array()
'taxonomy' => array(),
'custom_fields' => array()
);

public $uploaded_images = array();
Expand Down
12 changes: 8 additions & 4 deletions includes/publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public function create_post( $post_id, $item_slug, $item_props, $parent ){
$post_excerpt = empty( $front_matter[ 'post_excerpt' ] ) ? '' : $front_matter[ 'post_excerpt' ];
$menu_order = empty( $front_matter[ 'menu_order' ] ) ? 0 : $front_matter[ 'menu_order' ];
$taxonomy = $front_matter[ 'taxonomy' ];
$custom_fields = $front_matter[ 'custom_fields' ];

$sha = $item_props[ 'sha' ];
$github_url = $item_props[ 'github_url' ];
Expand All @@ -142,12 +143,18 @@ public function create_post( $post_id, $item_slug, $item_props, $parent ){
$post_excerpt = '';
$menu_order = 0;
$taxonomy = array();
$custom_fields = array();

$content = '';
$sha = '';
$github_url = '';
}

$meta_input = array_merge( $custom_fields, array(
'sha' => $sha,
'github_url' => $github_url
));

$post_details = array(
'ID' => $post_id,
'post_title' => $post_title,
Expand All @@ -159,10 +166,7 @@ public function create_post( $post_id, $item_slug, $item_props, $parent ){
'post_excerpt' => $post_excerpt,
'post_parent' => $parent,
'menu_order' => $menu_order,
'meta_input' => array(
'sha' => $sha,
'github_url' => $github_url
)
'meta_input' => $meta_input
);

$new_post_id = wp_insert_post( $post_details );
Expand Down
11 changes: 9 additions & 2 deletions includes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public static function edit_link( $atts ){
$atts = shortcode_atts( array(
'post_id' => $current_post_id,
'text' => 'Edit this page',
'icon' => '<i class="fas fa-pen"></i> &nbsp; '
'icon' => '<i class="fas fa-pen"></i> &nbsp; ',
'auto_p' => false
), $atts );

if( empty( $atts[ 'post_id' ] ) ){
Expand All @@ -37,7 +38,13 @@ public static function edit_link( $atts ){

$github_url = $meta[ 'github_url' ][0];

return '<a href="' . $github_url . '" class="giw-edit_link" target="_blank" rel="noreferrer noopener">' . $atts[ 'icon' ] . $atts[ 'text' ] . '</a>';
$link = '<a href="' . $github_url . '" class="giw-edit_link" target="_blank" rel="noreferrer noopener">' . $atts[ 'icon' ] . $atts[ 'text' ] . '</a>';

if( $atts[ 'auto_p' ] ){
return '<p>' . $link . '</p>';
}else{
return $link;
}

}

Expand Down
7 changes: 7 additions & 0 deletions includes/webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static function init(){
register_rest_route( 'giw/v1', '/publish', array(
'methods' => 'POST',
'callback' => array( __CLASS__, 'handle_webhook'),
'permission_callback' => array( __CLASS__, 'check_permission' )
));
});

Expand Down Expand Up @@ -83,6 +84,12 @@ public static function error( $code, $message, $data ){
return new WP_Error( $code, $message, $data );
}

public static function check_permission( $request ){
// No authentication needed right now. The main callback has various checks on the requestor.
// TODO - Move the checks in main callback here
return true;
}

}

GIW_Webhook::init();
Expand Down
21 changes: 13 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Git it Write is WordPress plugin which allows to publish the markdown files present in a Github repository to your WordPress site. So with this plugin, whenever the files are added, updated in the repository the WordPress post will be added, updated accordingly.

This plugin is inspired from static site generators like `Jekyll`, `Next.js`, `Gatsby.js` on how content is written is markdown. This is a similar idea for WordPress where markdown data is parsed from Github and published as posts.

**Live example:** [Source github repository](https:/vaakash/aakash-web) (`/docs/` folder) to [Posts published](https://www.aakashweb.com/docs/)

This allows people to collaborate with the post, share edits and suggestions in Github which when pulled the WordPress post will be updated automatically.

If a repository has files in the below structure,
Expand All @@ -20,21 +24,21 @@ Then below posts will be created like below (if permalinks are configured and th
https:\\example.com\docs\guide\getting-started\
https:\\example.com\help\faq\

### What is the use of this plugin ?
### 🎲 What is the use of this plugin ?

* Publish posts using the files in your Github repository.
* Write your posts in Markdown format.
* Write your posts on your desktop application (Notepad++, Sublime Text, Visual studio code).
* Collaborate, involve communities on the files in Github and publish them on WordPress.
* All the advantages of Git and it's version management system.

### Some use cases
### 🚀 Some use cases

* Can be used for documentation posts, FAQs, Wikis etc.
* Write blog posts.
* Any articles which may need community involvement.

### Features
### Features

* Markdown will be processed and post will be published as HTML.
* Images used in the source file will be uploaded to WordPress.
Expand All @@ -43,21 +47,22 @@ Then below posts will be created like below (if permalinks are configured and th
* Webhook support (whenever repository is changed, it updates the plugin to pull the latest changes and publish the posts)
* Add multiple repositories.
* Publish to any post type.
* Posts are published in hierarchial manner if they are under folders. Example: a file dir1/hello.md will be posted as dir1/hello/ in WordPress if the post type supports hierarchy.
* Posts are published in hierarchial manner if they are under folders. Example: a file `dir1/hello.md` will be posted as `dir1/hello/` in WordPress if the post type supports hierarchy.
* Support for post metadata like setting tags, categories, custom fields.

### Note
### Note

* Only Markdown files will be pulled and published right now
* Posts won't be deleted when it's source file is deleted on Github.
* It is preferred to have a permalink structure.
* It is preferred to select a post type which supports hierarchy.
* Images have to present only in `_images` folder in the repository root. Markdown files have to relatively use them in the file.

### Recommendation
### 🥗 Recommendation

It is recommended that a permalink structure is enabled in the WordPress site so that, if you have file under `docs\reference\my-post.md` then a post is published like `https://example.com/docs/reference/my-post/`. This will be the result when post type has hierarchy support. They will be posted level by level for every folder in the repository. The folder's post will be taken from the `index.md` file if exists under that folder.

### Using the plugin
### 🏃‍♂️ Using the plugin

1. Have a Github repository where all the source files (markdown files) are maintained (organized in folders if needed the exact structure)
1. In the plugin settings page, click add a new repository.
Expand All @@ -68,7 +73,7 @@ It is recommended that a permalink structure is enabled in the WordPress site so

### Links

* [FAQ](https://www.aakashweb.com/docs/git-it-write/)
* [Documentation](https://www.aakashweb.com/docs/git-it-write/)
* [Support forum/Report bugs](https://www.aakashweb.com/forum/)
* [Donate](https://www.paypal.me/vaakash/)

Expand Down
30 changes: 20 additions & 10 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ License: GPLv2 or later
Requires PHP: 5.3
Requires at least: 4.4
Tested up to: 5.5
Stable tag: 1.1
Stable tag: 1.2

Publish markdown files present in a Github repository as posts to WordPress automatically

Expand All @@ -18,6 +18,10 @@ Publish markdown files present in a Github repository as posts to WordPress auto

Git it Write allows to publish the markdown files present in a Github repository to your WordPress site. So with this plugin, whenever the files are added, updated in the repository the WordPress post will be added, updated accordingly.

This plugin is inspired from static site generators like `Jekyll`, `Next.js`, `Gatsby.js` on how content is written is markdown. This is a similar idea for WordPress where markdown files are parsed from Github and published as posts.

**Live example:** [Source github repository](https:/vaakash/aakash-web) (`/docs/` folder) to [Posts published](https://www.aakashweb.com/docs/)

This allows people to collaborate with the post, share edits and suggestions in Github which when pulled the WordPress post will be updated automatically.

If a repository has files in the below structure,
Expand All @@ -31,26 +35,25 @@ If a repository has files in the below structure,

Then below posts will be created like below (if permalinks are configured and the post type supports "hierarchy" i.e creating posts level by level (example: pages))


https:\\example.com\docs\guide\introduction\
https:\\example.com\docs\guide\getting-started\
https:\\example.com\help\faq\

### What is the use of this plugin ?
### 🎲 What is the use of this plugin ?

* Publish posts using the files in your Github repository.
* Write your posts in Markdown format.
* Write your posts on your desktop application (Notepad++, Sublime Text, Visual studio code).
* Collaborate, involve communities on the files in Github and publish them on WordPress.
* All the advantages of Git and it's version management system.

### Some use cases
### 🚀 Some use cases

* Can be used for documentation posts, FAQs, Wikis etc.
* Write blog posts.
* Any articles which may need community involvement.

### Features
### Features

* Markdown will be processed and post will be published as HTML.
* Images used in the source file will be uploaded to WordPress.
Expand All @@ -59,21 +62,22 @@ Then below posts will be created like below (if permalinks are configured and th
* Webhook support (whenever repository is changed, it updates the plugin to pull the latest changes and publish the posts)
* Add multiple repositories.
* Publish to any post type.
* Posts are published in hierarchial manner if they are under folders. Example: a file dir1/hello.md will be posted as dir1/hello/ in WordPress if the post type supports hierarchy.
* Posts are published in hierarchial manner if they are under folders. Example: a file `dir1/hello.md` will be posted as `dir1/hello/` in WordPress if the post type supports hierarchy.
* Support for post metadata like setting tags, categories, custom fields.

### Note
### Note

* Only Markdown files will be pulled and published right now
* Posts won't be deleted when it's source file is deleted on Github.
* It is preferred to have a permalink structure.
* It is preferred to select a post type which supports hierarchy.
* Images have to present only in `_images` folder in the repository root. Markdown files have to relatively use them in the file.

### Recommendation
### 🥗 Recommendation

It is recommended that a permalink structure is enabled in the WordPress site so that, if you have file under `docs\reference\my-post.md` then a post is published like `https://example.com/docs/reference/my-post/`. This will be the result when post type has hierarchy support. They will be posted level by level for every folder in the repository. The folder's post will be taken from the `index.md` file if exists under that folder.

### Using the plugin
### 🏃‍♂️ Using the plugin

1. Have a Github repository where all the source files (markdown files) are maintained (organized in folders if needed the exact structure)
1. In the plugin settings page, click add a new repository.
Expand All @@ -84,7 +88,7 @@ It is recommended that a permalink structure is enabled in the WordPress site so

### Links

* [FAQ](https://www.aakashweb.com/docs/git-it-write/)
* [Documentation](https://www.aakashweb.com/docs/git-it-write/)
* [Support forum/Report bugs](https://www.aakashweb.com/forum/)
* [Donate](https://www.paypal.me/vaakash/)
* [Contribute on Github](https:/vaakash/git-it-write)
Expand Down Expand Up @@ -132,6 +136,12 @@ Yes, if you want to pull posts from the a folder in a repository then you can sp

## Changelog

### 1.2
* New: Support for custom fields
* New: New shortcode attribute in `[giw_edit_link]` to automatically wrap in `p` tag.
* Fix: Added permission callback for the webhook REST API.
* Fix: Minor admin UI enhancements.

### 1.1
* New: Support for Parsedown extra

Expand Down

0 comments on commit 7d79615

Please sign in to comment.