Skip to content

Commit 92c8f8d

Browse files
committed
readthedocs 1st try
1 parent 44998fa commit 92c8f8d

File tree

2,013 files changed

+362
-145515
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,013 files changed

+362
-145515
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ __MACOSX
55
.idea
66
**/ebook
77
**/bbs
8-
.gitignore
8+
.gitignore
9+
_static
10+
_templates
11+
*.swp
12+
*.pyc
13+
__pycache__
14+
thu_cst_cracker.egg-info

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

README.md

Lines changed: 3 additions & 1 deletion

make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

setup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python3
2+
3+
import os, subprocess
4+
from setuptools import setup
5+
6+
subprocess.check_call('python3 ./source/gen.py --root . --output source'.split())
7+
8+
setup(
9+
name='thu-cst-cracker',
10+
description='frontend generator',
11+
install_requires=['sphinx-markdown-tables'],
12+
)

source/conf.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
# import os
14+
# import sys
15+
# sys.path.insert(0, os.path.abspath('.'))
16+
17+
18+
# -- Project information -----------------------------------------------------
19+
20+
project = 'THU-CST-Cracker'
21+
copyright = '2020, PKUanonym'
22+
author = 'PKUanonym'
23+
24+
25+
# -- General configuration ---------------------------------------------------
26+
'''import recommonmark
27+
from recommonmark.transform import AutoStructify
28+
29+
# At the bottom of conf.py
30+
def setup(app):
31+
app.add_config_value('recommonmark_config', {
32+
'url_resolver': lambda url: github_doc_root + url,
33+
'auto_toc_tree_section': 'Contents',
34+
}, True)
35+
app.add_transform(AutoStructify)
36+
'''# Add any Sphinx extension module names here, as strings. They can be
37+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
38+
# ones.
39+
extensions = ['recommonmark', 'sphinx_markdown_tables']
40+
source_suffix = ['.rst', '.md']
41+
# Add any paths that contain templates here, relative to this directory.
42+
templates_path = ['_templates']
43+
44+
# The language for content autogenerated by Sphinx. Refer to documentation
45+
# for a list of supported languages.
46+
#
47+
# This is also used if you do content translation via gettext catalogs.
48+
# Usually you set "language" from the command line for these cases.
49+
language = 'zh'
50+
51+
# List of patterns, relative to source directory, that match files and
52+
# directories to ignore when looking for source files.
53+
# This pattern also affects html_static_path and html_extra_path.
54+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
55+
56+
57+
# -- Options for HTML output -------------------------------------------------
58+
59+
# The theme to use for HTML and HTML Help pages. See the documentation for
60+
# a list of builtin themes.
61+
#
62+
import sphinx_rtd_theme
63+
html_theme = "sphinx_rtd_theme"
64+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
65+
66+
# Add any paths that contain custom static files (such as style sheets) here,
67+
# relative to this directory. They are copied after the builtin static files,
68+
# so a file named "default.css" will overwrite the builtin "default.css".
69+
html_static_path = ['_static']
70+
master_doc = 'index'

source/gen.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env python3
2+
3+
import os, argparse
4+
from os.path import sep
5+
6+
EXCLUDE = ['.git', '.gitignore', 'LICENSE', 'Makefile', 'make.bat', 'setup.py', 'source', 'thu_cst_cracker.egg-info']
7+
README_MD = ['README.md', 'readme.md']
8+
EXT = '.md'
9+
PREFIX = 'https://github.com/PKUanonym/REKCARC-TSC-UHT/blob/master/'
10+
rst = '''Welcome to THU-CST-Cracker!
11+
===========================================
12+
13+
.. toctree::
14+
:maxdepth: 2
15+
:caption: Contents:
16+
17+
TOC
18+
19+
Indices and tables
20+
==================
21+
22+
* :ref:`genindex`
23+
* :ref:`modindex`
24+
* :ref:`search`
25+
'''
26+
27+
def name_filter(s):
28+
return s.replace('_', '\\_')
29+
30+
def url_filter(s, p):
31+
c = 'tree' if os.path.isdir(s) else 'blob'
32+
return PREFIX.replace('blob', c) + s.replace(p, sep.join(p.split(sep)[-2:])).replace('(', '%28').replace(')', '%29').replace(' ', '%20').replace(EXT, '%2e%6d%64')
33+
34+
def get_all(d):
35+
_all = [os.path.join(d, i) for i in os.listdir(d)]
36+
files = [i for i in _all if os.path.isfile(i)]
37+
dirs = [i for i in _all if os.path.isdir(i)]
38+
files.sort()
39+
dirs.sort()
40+
return files, dirs
41+
42+
def get_course(root, cur, depth=0, threshold=30):
43+
files, dirs = get_all(cur)
44+
file_num = 0
45+
md_dir, md_file = '', ''
46+
for i in dirs:
47+
d_md, d_num = get_course(root, i, depth + 1)
48+
if depth >= 2 and d_num > threshold:
49+
files.append(i)
50+
print(depth, d_num, i)
51+
else:
52+
md_dir += f'{" " * depth}- [{name_filter(i.split(sep)[-1])}]({url_filter(i, root)})\n'
53+
md_dir += d_md
54+
file_num += d_num
55+
files.sort()
56+
for i in files:
57+
file_num += 1
58+
if i.split(sep)[-1] in README_MD and depth == 0:
59+
md_file = open(i).read().replace('#', '\t') + '\n\n' + md_file
60+
else:
61+
md_file += f'{" " * depth}- [{name_filter(i.split(sep)[-1])}]({url_filter(i, root)})\n'
62+
md = md_file + md_dir
63+
return md, file_num
64+
65+
def get_semester(cur):
66+
md = ''
67+
files, dirs = get_all(cur)
68+
for i in files:
69+
if i.endswith(EXT):
70+
md += f'{open(i).read()}\n\n'
71+
for i in files:
72+
if not i.endswith(EXT):
73+
md += f'[{name_filter(i.split(sep)[-1])}]({url_filter(i, cur)})\n\n'
74+
for i in dirs:
75+
d_md, d_num = get_course(i, i)
76+
md += f'## [{name_filter(i.split(sep)[-1])}]({url_filter(i, cur)})\n\n{d_md}\n\n'
77+
return md
78+
79+
def gen_md(d, n, m):
80+
if 'README' not in n:
81+
m = f'# {n.replace(EXT, "").split(sep)[-1]}\n\n{m}'
82+
if not n.endswith(EXT):
83+
n += EXT
84+
print(d, n)
85+
open(os.path.join(d, n), 'w').write(m)
86+
87+
if __name__ == '__main__':
88+
parser = argparse.ArgumentParser()
89+
parser.add_argument("--root", type=str, default='REKCARC-TSC-UHT')
90+
parser.add_argument("--output", type=str, default='.')
91+
args = parser.parse_args()
92+
files, dirs = get_all(args.root)
93+
files = [i for i in files if i.split(sep)[-1] not in EXCLUDE]
94+
dirs = [i for i in dirs if i.split(sep)[-1] not in EXCLUDE]
95+
print(files)
96+
print(dirs)
97+
if not os.path.exists(args.output):
98+
os.makedirs(args.output)
99+
for i in files:
100+
gen_md(args.output, i.replace(args.root, '.'), open(i).read())
101+
for i in dirs:
102+
gen_md(args.output, i.replace(args.root, '.'), get_semester(i))
103+
_all = [i.replace(EXT, '').split(sep)[-1] for i in files + dirs]
104+
rst = rst.replace('TOC', '\n '.join(_all))
105+
rst = rst.replace('二', '无').replace('三', '二').replace('无', '三')
106+
open(os.path.join(args.output, 'index.rst'), 'w').write(rst)
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)