Fix regex for Gemini>Markdown link conversion
This commit is contained in:
parent
1cb79416c2
commit
d6f8e7b84e
1 changed files with 4 additions and 6 deletions
10
mkht.php
10
mkht.php
|
@ -82,18 +82,16 @@ foreach ($config['base-url'] as $url)
|
||||||
$feed = ob_get_clean();
|
$feed = ob_get_clean();
|
||||||
|
|
||||||
foreach ($files_dates as $src_page => $last_mod) {
|
foreach ($files_dates as $src_page => $last_mod) {
|
||||||
$dest_page = str_replace('/src/', '/', $src_page);
|
|
||||||
|
|
||||||
$content = file_get_contents($src_page);
|
$content = file_get_contents($src_page);
|
||||||
|
|
||||||
preg_match('/^# ?(?<title>.*)$/Dm', $content, $matches);
|
preg_match('/^# ?(?<title>.*)$/Dm', $content, $matches);
|
||||||
$title = $matches['title'] ?? NULL;
|
$title = $matches['title'] ?? NULL;
|
||||||
|
|
||||||
$path_parts = pathinfo($dest_page);
|
$path_parts = pathinfo(str_replace('/src/', '/', $src_page));
|
||||||
|
|
||||||
$base_filepath = $path_parts['dirname'] . '/' . $path_parts['filename'];
|
$base_filepath = $path_parts['dirname'] . '/' . $path_parts['filename'];
|
||||||
|
|
||||||
if (!file_exists($dest_page) OR (filemtime($src_page) > filemtime($dest_page)) OR $opt['force']) {
|
if (!file_exists($base_filepath . '.html') OR (filemtime($src_page) > filemtime($base_filepath . '.html')) OR $opt['force']) {
|
||||||
echo 'Compiling ' . $src_page . ' ' . date("Y-m-d H:i:s", $last_mod) . LF;
|
echo 'Compiling ' . $src_page . ' ' . date("Y-m-d H:i:s", $last_mod) . LF;
|
||||||
|
|
||||||
// Create parent directory if needed
|
// Create parent directory if needed
|
||||||
|
@ -109,7 +107,7 @@ foreach ($files_dates as $src_page => $last_mod) {
|
||||||
// Convert Gemtext to Markdown
|
// Convert Gemtext to Markdown
|
||||||
if ($path_parts['extension'] === 'gmi') {
|
if ($path_parts['extension'] === 'gmi') {
|
||||||
$content = preg_replace_callback(
|
$content = preg_replace_callback(
|
||||||
'/^=>\h*(?<addr>\H+)(:?\h+(?<title>\H+))?$/Dm',
|
'/^=>\h*(?<addr>\S+)(:?\h+(?<title>\V+))?$/m',
|
||||||
function ($matches) {
|
function ($matches) {
|
||||||
if (!str_contains($matches['addr'], ':') AND str_ends_with($matches['addr'], '.gmi'))
|
if (!str_contains($matches['addr'], ':') AND str_ends_with($matches['addr'], '.gmi'))
|
||||||
$matches['addr'] = substr($matches['addr'], 0, -3) . 'md';
|
$matches['addr'] = substr($matches['addr'], 0, -3) . 'md';
|
||||||
|
@ -121,7 +119,7 @@ foreach ($files_dates as $src_page => $last_mod) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile Markdown to HTML
|
// Compile Markdown to HTML
|
||||||
$process = proc_open('pandoc --fail-if-warnings -f markdown_phpextra-citations-native_divs-native_spans+abbreviations+hard_line_breaks+lists_without_preceding_blankline -t html --wrap none', [
|
$process = proc_open('pandoc --fail-if-warnings -f markdown_phpextra-citations-native_divs-native_spans+abbreviations+hard_line_breaks+lists_without_preceding_blankline -t html --wrap none', [
|
||||||
0 => ['pipe', 'r'],
|
0 => ['pipe', 'r'],
|
||||||
1 => ['pipe', 'w'],
|
1 => ['pipe', 'w'],
|
||||||
], $pipes);
|
], $pipes);
|
||||||
|
|
Loading…
Reference in a new issue