From 39ae33a06b1c46bbe3df8f22988a459fc2b35ef7 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 24 Feb 2023 09:17:48 -0500
Subject: [PATCH] build_categories: Default to Markdown.
---
build_categories.php | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/build_categories.php b/build_categories.php
index 923d6be..4d9c835 100755
--- a/build_categories.php
+++ b/build_categories.php
@@ -85,7 +85,7 @@ function build_category_lists($srcdir)
closedir($dirp);
}
-function write_category_list($fp, $pages)
+function write_category_list($fp, $pages, $ismediawiki)
{
ksort($pages, SORT_STRING|SORT_FLAG_CASE);
fputs($fp, "<!-- BEGIN CATEGORY LIST -->\n");
@@ -99,7 +99,11 @@ function write_category_list($fp, $pages)
fputs($fp, "* $letter\n");
}
*/
- fputs($fp, "* [[$p]]\n"); // !!! FIXME: mediawiki, for now.
+ if ($ismediawiki) {
+ fputs($fp, "* [[$p]]\n");
+ } else {
+ fputs($fp, "- [$p]($p)\n");
+ }
}
fputs($fp, "<!-- END CATEGORY LIST -->\n");
}
@@ -140,13 +144,20 @@ function handle_subdir($dname)
//print("CATEGORY '$cat':\n");
//print_r($pages);
- $path = "$dname/$cat.mediawiki"; // for now.
- $tmppath = "$dname/.$cat.mediawiki.tmp"; // for now.
- $contents = '';
+ // keep in MediaWiki format if it exists, start new pages in Markdown.
+ $ismediawiki = true;
+ $path = "$dname/$cat.mediawiki";
if (!file_exists($path)) {
- file_put_contents($path, "= $cat =\n\n<!-- BEGIN CATEGORY LIST -->\n<!-- END CATEGORY LIST -->\n\n");
+ $ismediawiki = false;
+ $path = "$dname/$cat.md";
+ if (!file_exists($path)) {
+ file_put_contents($path, "# $cat\n\n<!-- BEGIN CATEGORY LIST -->\n<!-- END CATEGORY LIST -->\n\n");
+ }
}
+ $tmppath = "$path.tmp";
+ $contents = '';
+
$in = fopen($path, "r");
if ($in === false) {
print("Failed to open '$path' for reading\n");
@@ -188,7 +199,7 @@ function handle_subdir($dname)
fclose($in);
if (!$wrote_list) {
- write_category_list($out, $pages);
+ write_category_list($out, $pages, $ismediawiki);
}
fclose($out);