Skip to content

Commit

Permalink
feat: add summary for easier usage
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-jerry-ye committed Jan 16, 2025
1 parent 83d055f commit ef3bcb4
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ build:
os: ubuntu-22.04
tools:
python: "3.13"
jobs:
pre_build:
- python3 next/llm.py

sphinx:
configuration: next/conf.py
Expand Down
3 changes: 2 additions & 1 deletion next/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
_build
*.mo
__pycache__
.env
.env
download
2 changes: 1 addition & 1 deletion next/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
extensions = ['myst_parser', 'lexer', 'check', 'indent', 'sphinx_copybutton']

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

smartquotes_excludes = {
'builders': ['man', 'text', 'markdown', 'latex'],
Expand Down
2 changes: 2 additions & 0 deletions next/example/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Here are some examples built with MoonBit.

[Summary of this section](path:/download/example/summary.md)

```{toctree}
:maxdepth: 2
:caption: Contents:
Expand Down
2 changes: 2 additions & 0 deletions next/language/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ When MoonBit reaches beta, it means any backwards-incompatible changes will be s
- State of the art compile-time performance.
- Simple but practical, data-oriented language design.

[Summary of this section](path:/download/language/summary.md)

```{toctree}
:hidden:
introduction
Expand Down
69 changes: 56 additions & 13 deletions next/llm.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,60 @@
import os
import sys

BUILD_DIR="_build/markdown"

filenames = ["index.md", "tutorial/tour.md", "language/index.md", "language/introduction.md",
"language/fundamentals.md", "language/methods.md", "language/error-handling.md",
"language/packages.md", "language/tests.md", "language/docs.md", "language/ffi-and-wasm-host.md",
"language/derive.md", "language/async-experimental.md"]
def collect(directory, header_level, output_file):
def adjust_header(line, level):
if line.startswith('#'):
return '#' * level + line
return line

def process_file(filepath, level, output):
output.write(f"\n<!-- path: {filepath} -->\n")
with open(os.path.join(BUILD_DIR, filepath), "r") as file:
for line in file:
output.write(adjust_header(line, level))

index_path = os.path.join(directory, "index.md")
with open(index_path, "r") as index_file:
toctree_paths = []
collect_paths = False
for line in index_file:
line = line.strip()
if "toctree" in line:
collect_paths = True
continue
if collect_paths:
if line.startswith(":"):
continue
if line == "```":
break
toctree_paths.append(os.path.join(directory, f"{line}.md"))

with open(f"{BUILD_DIR}/llm.md", "w") as f:
print("# MoonBit Documentation", file=f)
for fname in filenames:
with open(f"{BUILD_DIR}/{fname}", "r") as g:
print(f"<!-- path: {fname} -->", file=f)
with open(output_file, "a") as output:
process_file(index_path, header_level, output)
for path in toctree_paths:
process_file(path, header_level + 1, output)

def llms_txt():
with open(f"{BUILD_DIR}/llm.md", "w") as f:
with open(f"{BUILD_DIR}/index.md", "r") as g:
print(f"<!-- path: index.md -->", file=f)
for line in g:
if line.startswith('#'):
f.write(f"#{line}")
else:
f.write(line)
f.write(line)

collect("tutorial", 1, f"{BUILD_DIR}/llm.md")
collect("language", 1, f"{BUILD_DIR}/llm.md")

def main():
os.system("make markdown")
llms_txt()
for directory in ["tutorial", "language", "toolchain", "example"]:
output_file = f"download/{directory}/summary.md"
os.makedirs(os.path.dirname(output_file), exist_ok=True)
if os.path.exists(output_file):
os.remove(output_file)
collect(directory, 0, output_file)

if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions next/toolchain/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Here are some manuals that may help you use the toolchains of the programming la
- VSCode extension
- ...

[Summary of this section](path:/download/toolchain/summary.md)

```{toctree}
:maxdepth: 2
:caption: Contents:
Expand Down
2 changes: 2 additions & 0 deletions next/tutorial/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Here are some tutorials that may help you learn the programming language:
- [An interactive tour with language basics](https://tour.moonbitlang.com)
- [Tour for Beginners](./tour.md)

[Summary of this section](path:/download/tutorial/summary.md)

```{toctree}
:hidden:
tour

0 comments on commit ef3bcb4

Please sign in to comment.