-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Website version of the book and related tooling.
- Loading branch information
Showing
147 changed files
with
19,129 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
format: | ||
npm run format | ||
|
||
check: | ||
npm run check | ||
|
||
website: | ||
python3 ./make-website-content.py | ||
|
||
books: | ||
./make-books.sh |
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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
""" | ||
Generate multiple Markdown documents from a single Markdown file by splitting it based on headings. | ||
This script is designed for creating pages on a website and provides results for multiple languages. | ||
Note: the number of headings per language must be the same. | ||
""" | ||
|
||
import os | ||
import re | ||
import shutil | ||
|
||
# INPUT_FILE_PATH = "./test-md/README.md" | ||
# OUTPUT_DIR_PATH = "./test-md/en" | ||
# INPUT_FILE_PATH_CN = "./test-md/README-zh_CN.md" | ||
# OUTPUT_DIR_PATH_CN = "./test-md/zh-cn" | ||
|
||
INPUT_FILE_PATH = "../README.md" | ||
OUTPUT_DIR_PATH = "../website/src/content/docs/book" | ||
|
||
INPUT_FILE_PATH_CN = "../README-zh_CN.md" | ||
OUTPUT_DIR_PATH_CN = "../website/src/content/docs/zh-cn/book" | ||
|
||
|
||
def manage_output_dir(path): | ||
if os.path.exists(path): | ||
shutil.rmtree(path) | ||
os.makedirs(path) | ||
|
||
|
||
def read_content_file(path): | ||
with open(path, "r") as file: | ||
lines = file.readlines() | ||
return lines | ||
|
||
|
||
def make_file_name(name): | ||
content_sanitized = re.sub(r"[^a-zA-Z0-9]+", "-", name.lower()).strip("-") | ||
return f"{content_sanitized}" | ||
|
||
|
||
def make_output_path(output_dir, file_name): | ||
return f"{output_dir}/{file_name}.md" | ||
|
||
|
||
def is_line_header_1_to_2(line): | ||
return re.match(r"^(#{1,2})\s+(.+)", line) | ||
|
||
|
||
def make_file_output_path(output_dir, name): | ||
file_name = make_file_name(name) | ||
output_file_path = make_output_path(output_dir, file_name) | ||
return output_file_path | ||
|
||
|
||
def make_markdown_page_metadata(order, header): | ||
return [ | ||
"---\n", | ||
f"title: {header}\n", | ||
"sidebar:\n", | ||
f" order: {order}\n", | ||
f" label: {order}. {header}\n", | ||
"---\n", | ||
"\n", | ||
] | ||
|
||
|
||
def save_content_to_file(path, lines): | ||
with open(path, "w") as output_file: | ||
output_file.writelines(lines) | ||
|
||
|
||
def save_pages_to_files(data_pages, master_headers, output_dir): | ||
for index, header in enumerate(master_headers): | ||
file = make_file_output_path(output_dir, header) | ||
save_content_to_file(file, data_pages[index]) | ||
|
||
|
||
def find_master_headers(lines): | ||
headers = [x for x in lines if is_line_header_1_to_2(x)] | ||
headers_clean = list(map(lambda x: make_file_name(x), headers)) | ||
return headers_clean | ||
|
||
|
||
def remove_markdown_anchors(markdown_text): | ||
pattern = r"\[(.*?)\]\(#[^\)]*\)" | ||
replacement = r"\1" | ||
transformed_text = re.sub(pattern, replacement, markdown_text) | ||
return transformed_text | ||
|
||
|
||
def split_content_by_headings(lines): | ||
current_content = [] | ||
in_page = False | ||
header_index = -1 | ||
content_result = [] | ||
|
||
for line in lines: | ||
is_header_match = is_line_header_1_to_2(line) | ||
if is_header_match: | ||
header_text = is_header_match.group(2).strip() | ||
header_index += 1 | ||
if not in_page: | ||
in_page = True | ||
current_content.extend( | ||
make_markdown_page_metadata(header_index + 1, header_text) | ||
) | ||
else: | ||
content_result.extend([current_content]) | ||
current_content = [] | ||
in_page = True | ||
current_content.extend( | ||
make_markdown_page_metadata(header_index + 1, header_text) | ||
) | ||
else: | ||
line_new = remove_markdown_anchors(line) | ||
current_content.append(line_new) | ||
|
||
header_index += 1 | ||
content_result.extend([current_content]) | ||
|
||
return content_result | ||
|
||
|
||
content_lines_master = read_content_file(INPUT_FILE_PATH) | ||
master_headers = find_master_headers(content_lines_master) | ||
|
||
|
||
def process(base_input, base_output): | ||
manage_output_dir(base_output) | ||
content_lines = read_content_file(base_input) | ||
data_pages = split_content_by_headings( | ||
content_lines, | ||
) | ||
save_pages_to_files(data_pages, master_headers, base_output) | ||
print(f"A total of: {len(master_headers)} files were at: {base_output}") | ||
|
||
|
||
process(INPUT_FILE_PATH, OUTPUT_DIR_PATH) | ||
|
||
process(INPUT_FILE_PATH_CN, OUTPUT_DIR_PATH_CN) |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# 简洁 TypeScript 书 | ||
TypeScript 有效开发简明指南。 **免费和开源**。 | ||
## 创建文件和文件夹 | ||
可使用 按钮访问文件资源管理器。 | ||
## 切换到另一个文件 | ||
您的所有文件和文件夹都在文件资源管理器中显示为树。 您可以通过单击树中的文件从一个文件切换到另一个文件。 | ||
### 新标题 | ||
一些家长内容。 | ||
#### 嵌套内容 1 | ||
更多内容在这里。 | ||
##### 嵌套内容 2 | ||
内容甚至更多。 |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# The Concise TypeScript Book | ||
A Concise Guide to Effective Development in TypeScript. **Free and Open Source**. | ||
## Create files and folders | ||
The file explorer is accessible using the button. | ||
## Switch to another file | ||
All your files and folders are presented as a tree in the file explorer. You can switch from one to another by clicking a file in the tree. | ||
### New title | ||
Some parent content. | ||
#### Nested content 1 | ||
More content here. | ||
##### Nested content 2 | ||
Even more content. |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# build output | ||
dist/ | ||
# generated types | ||
.astro/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
||
# logs | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
|
||
|
||
# environment variables | ||
.env | ||
.env.production | ||
|
||
# macOS-specific files | ||
.DS_Store |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
v19.7.0 |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 4, | ||
"semi": true, | ||
"singleQuote": true, | ||
"printWidth": 80, | ||
"arrowParens": "avoid" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"recommendations": ["astro-build.astro-vscode"], | ||
"unwantedRecommendations": [] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"command": "./node_modules/.bin/astro dev", | ||
"name": "Development server", | ||
"request": "launch", | ||
"type": "node-terminal" | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Starlight Starter Kit: Basics | ||
|
||
[![Built with Starlight](https://astro.badg.es/v2/built-with-starlight/tiny.svg)](https://starlight.astro.build) | ||
|
||
``` | ||
npm create astro@latest -- --template starlight | ||
``` | ||
|
||
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/starlight/tree/main/examples/basics) | ||
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/starlight/tree/main/examples/basics) | ||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fwithastro%2Fstarlight%2Ftree%2Fmain%2Fexamples%2Fbasics&project-name=my-starlight-docs&repository-name=my-starlight-docs) | ||
|
||
> 🧑🚀 **Seasoned astronaut?** Delete this file. Have fun! | ||
## 🚀 Project Structure | ||
|
||
Inside of your Astro + Starlight project, you'll see the following folders and files: | ||
|
||
``` | ||
. | ||
├── public/ | ||
├── src/ | ||
│ ├── assets/ | ||
│ ├── content/ | ||
│ │ ├── docs/ | ||
│ │ └── config.ts | ||
│ └── env.d.ts | ||
├── astro.config.mjs | ||
├── package.json | ||
└── tsconfig.json | ||
``` | ||
|
||
Starlight looks for `.md` or `.mdx` files in the `src/content/docs/` directory. Each file is exposed as a route based on its file name. | ||
|
||
Images can be added to `src/assets/` and embedded in Markdown with a relative link. | ||
|
||
Static assets, like favicons, can be placed in the `public/` directory. | ||
|
||
## 🧞 Commands | ||
|
||
All commands are run from the root of the project, from a terminal: | ||
|
||
| Command | Action | | ||
| :------------------------ | :----------------------------------------------- | | ||
| `npm install` | Installs dependencies | | ||
| `npm run dev` | Starts local dev server at `localhost:4321` | | ||
| `npm run build` | Build your production site to `./dist/` | | ||
| `npm run preview` | Preview your build locally, before deploying | | ||
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` | | ||
| `npm run astro -- --help` | Get help using the Astro CLI | | ||
|
||
## 👀 Want to learn more? | ||
|
||
Check out [Starlight’s docs](https://starlight.astro.build/), read [the Astro documentation](https://docs.astro.build), or jump into the [Astro Discord server](https://astro.build/chat). |
Oops, something went wrong.