Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements (see PR) #298

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion jekyll-export-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,54 @@
*
* Must be run in the wordpress-to-jekyll-exporter/ directory.
*/
require '../../../wp-load.php';

// Uncomment for extra replace options

$wordpress_path = "../../../";
//$wordpress_path = "/home/wordpress/";
benbalter marked this conversation as resolved.
Show resolved Hide resolved

require $wordpress_path . 'wp-load.php';
require_once 'jekyll-exporter.php'; // Ensure plugin is "activated".

$config["site_url"] = "https://www.mywebsite.fr/";
benbalter marked this conversation as resolved.
Show resolved Hide resolved

$config["extra_remove_site_url"] = $config["site_url"]; // Will remove site url to get relative URLs
$config['extra_code'] = true; // Will retrieve lang and protect pre/code
$config['extra_img_style'] = true; // Will retrieve style from image
$config['extra_tag_spoiler'] = true; // Will convert spoiler tags
benbalter marked this conversation as resolved.
Show resolved Hide resolved

//$config['force_dest_dir'] = "/dest-path/"; // "_export/"; // Force destination directory to relative one (without temp folder, will deactivate zip)


if ( php_sapi_name() !== 'cli' ) {
wp_die( 'Jekyll export must be run via the command line or administrative dashboard.' );
}

add_filter( 'the_content', function($contents) {
benbalter marked this conversation as resolved.
Show resolved Hide resolved

if ($config["extra_remove_site_url"]) $contents = preg_replace("!${$config['extra_remove_site_url']}!",'', $contents);

if ($config['extra_code']) {
$contents = preg_replace('!<span[^>]*crayon-inline[^>]*>([^<]*)</span>!','<code>\1</code>', $contents);
$contents = preg_replace('!class="lang:default!','class="', $contents);
$contents = preg_replace('!class="lang:!','class="language-', $contents);
$contents = preg_replace('!<pre([^>]*)><code>!','<pre\1>', $contents);
$contents = preg_replace('!</code></pre>!','</pre>', $contents);
$contents = preg_replace('!<pre([^>]*)>!','<pre><code \1>', $contents);
$contents = preg_replace('!</pre[^>]*>!','</code></pre>', $contents);
}
if ($config['extra_img_style']) {
$contents = preg_replace('!(<img[^>]*alignright[^>]*/>)!','\1{: .img-right}', $contents);
$contents = preg_replace('!(<img[^>]*aligncenter[^>]*/>)!','\1{: .img-center}', $contents);
$contents = preg_replace('!(<img[^>]*aligncenter[^>]*/>)!','\1{: .img-center}', $contents);
}
if ($config['extra_tag_spoiler']) {
$contents = preg_replace('!\[su_spoiler title="([^"]*)" [^\]]*\]!',"<details markdown=\"1\"><summary>\\1</summary>", $contents);
$contents = preg_replace('!\[/su_spoiler\]!',"</details>", $contents);
}

return $contents;
});

$jekyll_export = new Jekyll_Export();
$jekyll_export->export();
Loading