-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add summary for easier usage (#426)
- Loading branch information
1 parent
83d055f
commit cb21840
Showing
12 changed files
with
150 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
_build | ||
*.mo | ||
__pycache__ | ||
.env | ||
.env | ||
download |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.