Skip to content

Commit 2676a3f

Browse files
committed
[conf] Store redirects config in yaml file
1 parent cd8d7f7 commit 2676a3f

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

_conf/redirect.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# sphinx_reredirects configuration for HTML builder.
2+
# See also: https://documatt.com/sphinx-reredirects/usage.html
3+
4+
# source (docname): target (html page)
5+
notes/6-lectures-on-sketch: /notes/zxsys/6-lectures-on-sketch.html
6+
notes/leetcode/index: /notes/writeups/leetcode/index.html
7+
notes/2021-interview/index: /notes/writeups/2021-interview/index.html

_utils/migrate-to-permnotes

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# set -x
33

44
root=$(git rev-parse --show-toplevel)
55
cd $root
66

77
eval "$(snippet integration --sh)"
8-
id=$(snippet_list --tags d --docname 'ronin/inbox/**')
8+
id=$(snippet_list --tags d)
99
file=$(snippet get $id --file)
10+
docname=$(snippet get $id --docname)
1011

11-
mv $file $root/p/$(basename $file)
12+
new_file="$root/p/$(basename $file)"
13+
new_docname="p/$(basename $docname)"
14+
15+
mv $file $new_file
16+
if [[ "$docname" != "ronin"* ]]; then
17+
echo "$docname: /$new_docname.html" >> ./_conf/redirect.yml
18+
fi
19+
20+
git add $file $new_file ./_conf/redirect.yml
21+
git diff HEAD

conf.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
from datetime import datetime
1717
from enum import Enum, auto
18+
import yaml
1819

1920
sys.path.insert(0, os.path.abspath('.'))
2021

@@ -466,11 +467,8 @@ def url(self) -> str:
466467
if D.is_public():
467468
extensions.append('sphinx_reredirects')
468469
# https://documatt.gitlab.io/sphinx-reredirects/usage.html
469-
redirects = {
470-
'notes/6-lectures-on-sketch': '/notes/zxsys/6-lectures-on-sketch.html',
471-
'notes/leetcode/index': '/notes/writeups/leetcode/index.html',
472-
'notes/2021-interview/index': '/notes/writeups/2021-interview/index.html',
473-
}
470+
with open('./_conf/redirect.yml') as data:
471+
redirects = yaml.safe_load(data)
474472

475473
# extensions.append('sphinxcontrib.images')
476474
# images_config = {

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ sphinxnotes-comboroles
2626
sphinxcontrib-globalsubs @ git+https://github.com/SilverRainZ/sphinxcontrib-globalsubs.git
2727
sphinx_simplepdf
2828
sphinxnotes-fasthtml
29+
pyyaml

0 commit comments

Comments
 (0)