Skip to content

Commit 941c2f5

Browse files
committed
Require .json.md extension for compound pages
1 parent a740786 commit 941c2f5

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

lib/gitdata/compound.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static function load ($paths)
2727
{
2828
$ret = null;
2929

30-
if (substr($paths[$i], -3) === '.md')
30+
if (substr($paths[$i], -8) === '.json.md')
3131
{
3232
$ret = self::load_compound($paths[$i]);
3333
}

lib/gitdata/models/page.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct ($compound)
6464

6565
if (isset($compound->info->_filename))
6666
{
67-
$this->permalink .= '/' . preg_replace('/\..*$/', '', $compound->info->_filename);
67+
$this->permalink .= '/' . preg_replace('/\.json\.md$/', '', $compound->info->_filename);
6868
}
6969

7070
if ($compound->content)
@@ -90,10 +90,11 @@ public function __construct ($compound)
9090
public static function find_by_path ($path)
9191
{
9292
$path = preg_replace('/^\//', '', $path);
93+
$path = preg_replace('/\/$/', '', $path);
94+
9395
$compound = \GitData\Compound::load(array(
9496
'pages/' . $path . '/info.json',
95-
'pages/' . $path . '/content.md',
96-
'pages/' . $path . '.md'
97+
'pages/' . $path . '.json.md'
9798
));
9899

99100
if ($compound)
@@ -147,6 +148,12 @@ private static function get_blog_index_by_year ($year)
147148
git_tree_walk($tree, GIT_TREEWALK_PRE, function ($_1, $entry, &$index) use ($year)
148149
{
149150
$path = 'blog/' . $year . '/' . git_tree_entry_name($entry);
151+
152+
if (substr($path, -8) === '.json.md')
153+
{
154+
$path = substr($path, 0, -8);
155+
}
156+
150157
$page = Page::find_by_path($path);
151158

152159
if ($page)

lib/gitdata/models/wiki_page.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ public function __construct ($compound)
5252
$this->toc = $compound->content->get_toc();
5353
}
5454

55-
$this->permalink = preg_replace('/^wiki/', '', $compound->info->_basedir);
55+
$this->permalink = preg_replace('/^wiki/', '/', $compound->info->_basedir);
56+
$this->permalink = preg_replace('/[\/]+/', '/', $this->permalink);
5657

57-
if (isset($info->_filename))
58+
if (isset($compound->info->_filename))
5859
{
59-
$this->permalink .= preg_replace('/\..*$/', '', $compound->info->_filename);
60+
$this->permalink .= preg_replace('/\.json\.md$/', '', $compound->info->_filename);
6061
}
6162

6263
$this->github_history_url = 'https://github.com/axr/website-data';
@@ -84,7 +85,7 @@ public static function find_by_path ($path)
8485
$path = preg_replace('/^\//', '', $path);
8586
$compound = \GitData\Compound::load(array(
8687
'wiki/' . $path . '/info.json',
87-
'wiki/' . $path . '.md'
88+
'wiki/' . $path . '.json.md'
8889
));
8990

9091
if ($compound)
@@ -119,7 +120,7 @@ public static function list_all ($path)
119120
}
120121

121122
$item = preg_replace('/[\/]+/', '/', $path . '/' . $entry_name);
122-
$item = preg_replace('/(^\/|\.md$)/', '', $item);
123+
$item = preg_replace('/(^\/|(\.json)?\.md$)/', '', $item);
123124

124125
$page = WikiPage::find_by_path($item);
125126

@@ -166,8 +167,7 @@ public static function tree_entry_is_category ($entry)
166167
$filemode = git_tree_entry_filemode($entry);
167168
$name = git_tree_entry_name($entry);
168169

169-
if ($filemode == GIT_FILEMODE_BLOB &&
170-
substr($name, -4) == '.md' && $name != 'content.md')
170+
if ($filemode == GIT_FILEMODE_BLOB && substr($name, -8) == '.json.md')
171171
{
172172
$ret = true;
173173
return -1;

0 commit comments

Comments
 (0)