Skip to content

Commit ade055b

Browse files
Documentation: moved compute_page_id to md_utils
1 parent 0673712 commit ade055b

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

Doc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

Doc/md_filter.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,7 @@
22
import os
33
import re
44

5-
6-
def compute_page_id(root_dir, input_filepath):
7-
# Compute the file's absolute path and then its relative path from the root directory.
8-
abs_input_path = os.path.abspath(input_filepath)
9-
rel_path = os.path.relpath(abs_input_path, root_dir)
10-
# Remove the file extension.
11-
rel_path_no_ext, _ = os.path.splitext(rel_path)
12-
# Replace path separators with underscores.
13-
page_id = rel_path_no_ext.replace(os.sep, "_")
14-
return page_id
15-
5+
from md_utils import compute_page_id
166

177
def replace_special_symbols(text):
188
# Define your symbol mappings using Unicode escape sequences.

Doc/md_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
def compute_page_id(root_dir, input_filepath):
4+
"""
5+
Compute a unique page id based on the file's path relative to the project root.
6+
7+
For example, if input_filepath is:
8+
<root_dir>/Path/To/page.md
9+
then the returned page id becomes:
10+
Path_To_page
11+
""" # Compute the file's absolute path and then its relative path from the root directory.
12+
abs_input_path = os.path.abspath(input_filepath)
13+
rel_path = os.path.relpath(abs_input_path, root_dir)
14+
# Remove the file extension.
15+
rel_path_no_ext, _ = os.path.splitext(rel_path)
16+
# Replace path separators with underscores.
17+
page_id = rel_path_no_ext.replace(os.sep, "_")
18+
return page_id

0 commit comments

Comments
 (0)