Skip to content

Commit cb21840

Browse files
feat: add summary for easier usage (#426)
1 parent 83d055f commit cb21840

File tree

12 files changed

+150
-106
lines changed

12 files changed

+150
-106
lines changed

.readthedocs.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ build:
33
os: ubuntu-22.04
44
tools:
55
python: "3.13"
6+
jobs:
7+
pre_build:
8+
- cd next && python3 llm.py && cd ..
69

710
sphinx:
811
configuration: next/conf.py

next/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
_build
22
*.mo
33
__pycache__
4-
.env
4+
.env
5+
download

next/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
extensions = ['myst_parser', 'lexer', 'check', 'indent', 'sphinx_copybutton']
3232

3333
templates_path = ['_templates']
34-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', ".env", '.venv', "README.md", 'sources']
34+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', ".env", '.venv', "README.md", 'sources', 'download']
3535

3636
smartquotes_excludes = {
3737
'builders': ['man', 'text', 'markdown', 'latex'],

next/example/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Here are some examples built with MoonBit.
44

5+
[Download this section in Markdown](path:/download/example/summary.md)
6+
57
```{toctree}
68
:maxdepth: 2
79
:caption: Contents:

next/language/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ When MoonBit reaches beta, it means any backwards-incompatible changes will be s
1515
- State of the art compile-time performance.
1616
- Simple but practical, data-oriented language design.
1717

18+
[Download this section in Markdown](path:/download/language/summary.md)
19+
1820
```{toctree}
1921
:hidden:
2022
introduction

next/llm.py

+56-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
1+
import os
2+
import sys
3+
14
BUILD_DIR="_build/markdown"
25

3-
filenames = ["index.md", "tutorial/tour.md", "language/index.md", "language/introduction.md",
4-
"language/fundamentals.md", "language/methods.md", "language/error-handling.md",
5-
"language/packages.md", "language/tests.md", "language/docs.md", "language/ffi-and-wasm-host.md",
6-
"language/derive.md", "language/async-experimental.md"]
6+
def collect(directory, header_level, output_file):
7+
def adjust_header(line, level):
8+
if line.startswith('#'):
9+
return '#' * level + line
10+
return line
11+
12+
def process_file(filepath, level, output):
13+
output.write(f"\n<!-- path: {filepath} -->\n")
14+
with open(os.path.join(BUILD_DIR, filepath), "r") as file:
15+
for line in file:
16+
output.write(adjust_header(line, level))
17+
18+
index_path = os.path.join(directory, "index.md")
19+
with open(index_path, "r") as index_file:
20+
toctree_paths = []
21+
collect_paths = False
22+
for line in index_file:
23+
line = line.strip()
24+
if "toctree" in line:
25+
collect_paths = True
26+
continue
27+
if collect_paths:
28+
if line.startswith(":"):
29+
continue
30+
if line == "```":
31+
break
32+
toctree_paths.append(os.path.join(directory, f"{line}.md"))
733

8-
with open(f"{BUILD_DIR}/llm.md", "w") as f:
9-
print("# MoonBit Documentation", file=f)
10-
for fname in filenames:
11-
with open(f"{BUILD_DIR}/{fname}", "r") as g:
12-
print(f"<!-- path: {fname} -->", file=f)
34+
with open(output_file, "a") as output:
35+
process_file(index_path, header_level, output)
36+
for path in toctree_paths:
37+
process_file(path, header_level + 1, output)
38+
39+
def llms_txt():
40+
with open(f"{BUILD_DIR}/llm.md", "w") as f:
41+
with open(f"{BUILD_DIR}/index.md", "r") as g:
42+
print(f"<!-- path: index.md -->", file=f)
1343
for line in g:
14-
if line.startswith('#'):
15-
f.write(f"#{line}")
16-
else:
17-
f.write(line)
44+
f.write(line)
45+
46+
collect("tutorial", 1, f"{BUILD_DIR}/llm.md")
47+
collect("language", 1, f"{BUILD_DIR}/llm.md")
48+
49+
def main():
50+
os.system("make markdown")
51+
llms_txt()
52+
for directory in ["tutorial", "language", "toolchain", "example"]:
53+
output_file = f"download/{directory}/summary.md"
54+
os.makedirs(os.path.dirname(output_file), exist_ok=True)
55+
if os.path.exists(output_file):
56+
os.remove(output_file)
57+
collect(directory, 0, output_file)
58+
59+
if __name__ == "__main__":
60+
main()

next/locales/zh_CN/LC_MESSAGES/example.po

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: MoonBit Document \n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2025-01-03 11:03+0800\n"
11+
"POT-Creation-Date: 2025-01-16 15:44+0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language: zh_CN\n"
@@ -2711,7 +2711,7 @@ msgid ""
27112711
"Nevertheless, it is undoubtedly an intriguing technology!"
27122712
msgstr ""
27132713

2714-
#: ../../example/gmachine/index.md:7 ../../example/index.md:5
2714+
#: ../../example/gmachine/index.md:7 ../../example/index.md:7
27152715
#: ../../example/myers-diff/index.md:3 ../../example/segment-tree/index.md:13
27162716
msgid "Contents:"
27172717
msgstr "目录:"
@@ -2743,6 +2743,10 @@ msgstr "例子"
27432743
msgid "Here are some examples built with MoonBit."
27442744
msgstr "这里有一些用 MoonBit 构建的例子"
27452745

2746+
#: ../../example/index.md:5
2747+
msgid "[Download this section in Markdown](path:/download/example/summary.md)"
2748+
msgstr "[下载本章节的 Markdown 版本](path:/download/example/summary.md)"
2749+
27462750
#: ../../example/lambda/index.md:1
27472751
msgid "Lambda calculus"
27482752
msgstr "Lambda 演算"

next/locales/zh_CN/LC_MESSAGES/language.po

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: MoonBit Document \n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2025-01-10 17:54+0800\n"
11+
"POT-Creation-Date: 2025-01-16 15:44+0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language: zh_CN\n"
@@ -5693,6 +5693,10 @@ msgstr "先进的编译时性能。"
56935693
msgid "Simple but practical, data-oriented language design."
56945694
msgstr "简单且实用的数据导向语言设计。"
56955695

5696+
#: ../../language/index.md:18
5697+
msgid "[Download this section in Markdown](path:/download/language/summary.md)"
5698+
msgstr "[下载本章节的 Markdown 版本](path:/download/language/summary.md)"
5699+
56965700
#: ../../language/introduction.md:1
56975701
msgid "Introduction"
56985702
msgstr "概述"

next/locales/zh_CN/LC_MESSAGES/toolchain.po

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: MoonBit Document \n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2024-12-31 16:38+0800\n"
11+
"POT-Creation-Date: 2025-01-16 15:44+0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language: zh_CN\n"
@@ -19,7 +19,7 @@ msgstr ""
1919
"Content-Transfer-Encoding: 8bit\n"
2020
"Generated-By: Babel 2.16.0\n"
2121

22-
#: ../../toolchain/index.md:9 ../../toolchain/moon/index.md:3
22+
#: ../../toolchain/index.md:11 ../../toolchain/moon/index.md:3
2323
msgid "Contents:"
2424
msgstr "内容:"
2525

@@ -47,6 +47,10 @@ msgstr "VSCode扩展"
4747
msgid "..."
4848
msgstr ""
4949

50+
#: ../../toolchain/index.md:9
51+
msgid "[Download this section in Markdown](path:/download/toolchain/summary.md)"
52+
msgstr "[下载本章节的 Markdown 版本](path:/download/toolchain/summary.md)"
53+
5054
#: ../../toolchain/moon/commands.md:1
5155
msgid "Command-Line Help for `moon`"
5256
msgstr "`moon`的命令行帮助"

0 commit comments

Comments
 (0)