-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathdocmuck
More file actions
executable file
·135 lines (100 loc) · 4.27 KB
/
docmuck
File metadata and controls
executable file
·135 lines (100 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/python3
#
# To the extent possible under law, the person who associated CC0 with
# this project has waived all copyright and related or neighboring rights
# to this project.
#
# You should have received a copy of the CC0 legalcode along with this
# work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
#
# I got tired of mkdocs succumbing to bit rot, breaking backwards compatibility
# and it's byzyintine quirky syntax, so I rolled my own.
#
# This uses the same `mkdocs.yml` config file, so should be somewhat compatible
#
# The basic workflow is:
#
# * read in `mkdocs.yml` into CONFIG data structure
# * run through article list specified in CONFIG['nav']
# * for each file, use pandoc to convert to html:
# - allowing for "GitHub flavored Markdown", and "Pandoc flavored Markdown",
# depending on file extension (`.gfm`, `.md`, `.pdmd`)
# - pygments for code styling
# - rudimentary templating substitution (hardcoded to be `/dev_theme/base.html` with
# `{{page.content}}` keyword)
# * articles deposited in `site/` directory (ARTICLE_DST_DIR)
#
# That's it. Nothing fancy. Use `python -m http.server` in `site/` to test.
#
import re
import yaml
import os, sys
import json
import subprocess as sp
YAML_CONFIG = "./mkdocs.yml"
HTML_TEMPLATE = ""
CONFIG_DATA = {}
BASE_DIR = "dev_theme/"
HTML_TEMPLATE_FN = BASE_DIR + "base.html"
ARTICLE_SRC_DIR = "wiki/"
ARTICLE_DST_DIR = "site/"
#ARTICLE_LIST = [
# "index.md", "Textile-Cheat-Sheet.md", "Image-Resize.md",
# "Screenshots-Screencasts-Animated-Gifs.md", "ffmpeg-notes.md", "Unix-y-notes.md",
# "lattice-reduction.md", "GCode-Conversion.md", "Git-Rename-Master.md",
# "MkDocs-Quickstart.md", "GPG-Notes.md", "Git-Notes.md",
# "Shannon-Entropy.md", "Enabling-Server-HTTPS.md", "BGZF-Example.md",
# "Kelly-Criterion.md", "C-Project-Template.md", "Project-Organization.md",
# "File-Naming-Conventions.md", "Command-Line-Option-Loose-Standard.md", "PCB-Notes.md",
# "Coding-Style.md", "Energy-Consumption-Stats.md", "Simple-Sum.md",
# "Fisher-Yates-Shuffle.md", "Halting-Problem.md", "Assorted-Small-Probability-Problems.md",
# "Probability-Notes.md", "Amdahls-Law.md", "Is-It-Really-Open.md",
# "Number-Theory-Notes.md", "Arbitrary-Binary-Functions.md", "Empirical-Laws.md",
# "Food-CO2-Water.md", "SSH-Recipes.md", "Future-Predictions.md",
# "Diophantine-Approximation.md", "GCode-Common.md", "Misc-Math.md",
# "Socio-Economic-Definitions.md", "Bitcoin-Moon-Math.md", "Energy-Discussion.md",
# "AWK-Cheatsheet.pdmd", "Littlewood-Polynomials-Notes.md", "Useful-Tables.md",
# "Belief-Propagation.md", "Probability-Definitions.md", "Puzzle-Ribbon-Tiles.md",
# "Kullback-Leibler-Divergence.md", "Statistical-Mechanics-For-Computer-Scientists.md" ]
ARTICLE_LIST = []
with open(YAML_CONFIG) as fp:
try:
CONFIG_DATA = yaml.safe_load(fp)
except yaml.YAMLError as e:
print(e)
sys.exit(-1)
ARTICLE_LIST = CONFIG_DATA["nav"]
#print(json.dumps(CONFIG_DATA, indent=2))
#with open( CONFIG_DATA["theme"]["custom_dir"] + "base.html" ) as fp:
with open( HTML_TEMPLATE_FN ) as fp:
HTML_TEMPLATE = fp.read()
sp.call(['mkdir', '-p', ARTICLE_DST_DIR])
sp.call(['cp', '-r', BASE_DIR + 'js', ARTICLE_DST_DIR])
sp.call(['cp', '-r', BASE_DIR + 'css', ARTICLE_DST_DIR])
sp.call(['cp', '-r', BASE_DIR + 'img', ARTICLE_DST_DIR])
sp.call(['cp', '-r', ARTICLE_SRC_DIR + 'img', ARTICLE_DST_DIR])
sp.call(['cp', '-r', ARTICLE_SRC_DIR + 'src', ARTICLE_DST_DIR])
#print(HTML_TEMPLATE)
for base_md_fn in ARTICLE_LIST:
# default to github flavored markdown
#
input_fmt = "gfm"
input_article_sfx = ".md"
# `pdmd` == Pandoc flavored Markdown
#
if (re.search('\.pdmd$', base_md_fn)):
input_fmt = "markdown"
input_article_sfx = ".pdmd"
md_fn = ARTICLE_SRC_DIR + base_md_fn
tmp_fn = "/tmp/out_tmp.html"
#sp.call(['pandoc', '-f', input_fmt, '-o', tmp_fn, md_fn])
sp.call(['pandoc', '--highlight-style', 'pygments', '-f', input_fmt, '-o', tmp_fn, md_fn])
html_snippet = ""
with open(tmp_fn) as fp:
html_snippet = fp.read()
html_article = HTML_TEMPLATE
html_article = html_article.replace('{{page.content}}', html_snippet)
ARTICLE_FN = ARTICLE_DST_DIR + base_md_fn.replace(input_article_sfx, '.html')
print(ARTICLE_FN, "(", input_fmt, ")")
with open(ARTICLE_FN, "w") as fp:
fp.write(html_article)