Skip to content

Commit

Permalink
readthedocs 1st try
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinkle23897 committed Feb 2, 2020
1 parent 44998fa commit 92c8f8d
Show file tree
Hide file tree
Showing 2,013 changed files with 362 additions and 145,515 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ __MACOSX
.idea
**/ebook
**/bbs
.gitignore
.gitignore
_static
_templates
*.swp
*.pyc
__pycache__
thu_cst_cracker.egg-info
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[![](https://img.shields.io/github/issues-pr-closed-raw/PKUanonym/REKCARC-TSC-UHT.svg?style=flat)](https://github.com/PKUanonym/REKCARC-TSC-UHT/issues)
![](https://img.shields.io/github/repo-size/PKUanonym/REKCARC-TSC-UHT.svg?style=flat)

Web page: [REKCARC-TSC-UHT.readthedocs.io](https://REKCARC-TSC-UHT.readthedocs.io)

[浙江大学相关项目](https://github.com/QSCTech/zju-icicles)启发,创立了本项目。

由于本仓库未启用`git-lfs`,因此请不要上传单个超过100M的文件,否则commit无效。
Expand All @@ -14,7 +16,7 @@

如果您是清华大学学生,可移步 https://git.tsinghua.edu.cn/pkuanonym/REKCARC-TSC-UHT 进行查看并且能节约不少流量。

感谢对本项目贡献的同学:[Trinkle23897](https://github.com/trinkle23897)、[LJSthu](https://github.com/ljsthu)、[shyoshyo](https://github.com/shyoshyo)、[wuhaozhe](https://github.com/wuhaozhe)、[choumartin1234](https://github.com/choumartin1234)、[FztTony](https://github.com/FztTony/)、[VicaYang](https://github.com/VicaYang/)、[duzx16](https://github.com/duzx16/)、[zerotrac](https://github.com/zerotrac)、[gjz010](https://github.com/gjz010/)、[Recursion](https://github.com/RecursionSheep)、[linusboyle](https://github.com/linusboyle)、[namasikanam](https://github.com/namasikanam)、[JamesZhengYuyu](https://github.com/JamesZhengYuyu)、[zx1239856](https://github.com/zx1239856)、[yaoqs](https://github.com/yaoqs)、[heheda12345](https://github.com/heheda12345)、[MashPlant](https://github.com/MashPlant)、[lwpie](https://github.com/lwpie)、[cht33](https://github.com/cht33)、[chenweize1998](https://github.com/chenweize1998)、[will7101](https://github.com/will7101)、[UNIDY2002](https://github.com/UNIDY2002)……以及电脑前的您!
感谢对本项目贡献的同学:[Trinkle23897](https://github.com/trinkle23897)、[LJSthu](https://github.com/ljsthu)、[shyoshyo](https://github.com/shyoshyo)、[wuhaozhe](https://github.com/wuhaozhe)、[choumartin1234](https://github.com/choumartin1234)、[FztTony](https://github.com/FztTony/)、[VicaYang](https://github.com/VicaYang/)、[duzx16](https://github.com/duzx16/)、[zerotrac](https://github.com/zerotrac)、[gjz010](https://github.com/gjz010/)、[Recursion](https://github.com/RecursionSheep)、[linusboyle](https://github.com/linusboyle)、[namasikanam](https://github.com/namasikanam)、[JamesZhengYuyu](https://github.com/JamesZhengYuyu)、[zx1239856](https://github.com/zx1239856)、[yaoqs](https://github.com/yaoqs)、[heheda12345](https://github.com/heheda12345)、[MashPlant](https://github.com/MashPlant)、[lwpie](https://github.com/lwpie)、[cht33](https://github.com/cht33)、[chenweize1998](https://github.com/chenweize1998)、[will7101](https://github.com/will7101)、[UNIDY2002](https://github.com/UNIDY2002)、[yinhaoxuan](https://github.com/yinhaoxuan)、[zhengkw18](https://github.com/zhengkw18)、[rcy17](https://github.com/rcy17)、[prnake](https://github.com/prnake)、[qky18](https://github.com/qky18)……以及电脑前的您!

## 前言

Expand Down
35 changes: 35 additions & 0 deletions make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3

import os, subprocess
from setuptools import setup

subprocess.check_call('python3 ./source/gen.py --root . --output source'.split())

setup(
name='thu-cst-cracker',
description='frontend generator',
install_requires=['sphinx-markdown-tables'],
)
70 changes: 70 additions & 0 deletions source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'THU-CST-Cracker'
copyright = '2020, PKUanonym'
author = 'PKUanonym'


# -- General configuration ---------------------------------------------------
'''import recommonmark
from recommonmark.transform import AutoStructify
# At the bottom of conf.py
def setup(app):
app.add_config_value('recommonmark_config', {
'url_resolver': lambda url: github_doc_root + url,
'auto_toc_tree_section': 'Contents',
}, True)
app.add_transform(AutoStructify)
'''# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['recommonmark', 'sphinx_markdown_tables']
source_suffix = ['.rst', '.md']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'zh'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
import sphinx_rtd_theme
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
master_doc = 'index'
106 changes: 106 additions & 0 deletions source/gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env python3

import os, argparse
from os.path import sep

EXCLUDE = ['.git', '.gitignore', 'LICENSE', 'Makefile', 'make.bat', 'setup.py', 'source', 'thu_cst_cracker.egg-info']
README_MD = ['README.md', 'readme.md']
EXT = '.md'
PREFIX = 'https://github.com/PKUanonym/REKCARC-TSC-UHT/blob/master/'
rst = '''Welcome to THU-CST-Cracker!
===========================================
.. toctree::
:maxdepth: 2
:caption: Contents:
TOC
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
'''

def name_filter(s):
return s.replace('_', '\\_')

def url_filter(s, p):
c = 'tree' if os.path.isdir(s) else 'blob'
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')

def get_all(d):
_all = [os.path.join(d, i) for i in os.listdir(d)]
files = [i for i in _all if os.path.isfile(i)]
dirs = [i for i in _all if os.path.isdir(i)]
files.sort()
dirs.sort()
return files, dirs

def get_course(root, cur, depth=0, threshold=30):
files, dirs = get_all(cur)
file_num = 0
md_dir, md_file = '', ''
for i in dirs:
d_md, d_num = get_course(root, i, depth + 1)
if depth >= 2 and d_num > threshold:
files.append(i)
print(depth, d_num, i)
else:
md_dir += f'{" " * depth}- [{name_filter(i.split(sep)[-1])}]({url_filter(i, root)})\n'
md_dir += d_md
file_num += d_num
files.sort()
for i in files:
file_num += 1
if i.split(sep)[-1] in README_MD and depth == 0:
md_file = open(i).read().replace('#', '\t') + '\n\n' + md_file
else:
md_file += f'{" " * depth}- [{name_filter(i.split(sep)[-1])}]({url_filter(i, root)})\n'
md = md_file + md_dir
return md, file_num

def get_semester(cur):
md = ''
files, dirs = get_all(cur)
for i in files:
if i.endswith(EXT):
md += f'{open(i).read()}\n\n'
for i in files:
if not i.endswith(EXT):
md += f'[{name_filter(i.split(sep)[-1])}]({url_filter(i, cur)})\n\n'
for i in dirs:
d_md, d_num = get_course(i, i)
md += f'## [{name_filter(i.split(sep)[-1])}]({url_filter(i, cur)})\n\n{d_md}\n\n'
return md

def gen_md(d, n, m):
if 'README' not in n:
m = f'# {n.replace(EXT, "").split(sep)[-1]}\n\n{m}'
if not n.endswith(EXT):
n += EXT
print(d, n)
open(os.path.join(d, n), 'w').write(m)

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--root", type=str, default='REKCARC-TSC-UHT')
parser.add_argument("--output", type=str, default='.')
args = parser.parse_args()
files, dirs = get_all(args.root)
files = [i for i in files if i.split(sep)[-1] not in EXCLUDE]
dirs = [i for i in dirs if i.split(sep)[-1] not in EXCLUDE]
print(files)
print(dirs)
if not os.path.exists(args.output):
os.makedirs(args.output)
for i in files:
gen_md(args.output, i.replace(args.root, '.'), open(i).read())
for i in dirs:
gen_md(args.output, i.replace(args.root, '.'), get_semester(i))
_all = [i.replace(EXT, '').split(sep)[-1] for i in files + dirs]
rst = rst.replace('TOC', '\n '.join(_all))
rst = rst.replace('二', '无').replace('三', '二').replace('无', '三')
open(os.path.join(args.output, 'index.rst'), 'w').write(rst)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 92c8f8d

Please sign in to comment.