Skip to content

Commit 8ff5368

Browse files
committed
search bug fix arm-education#4
1 parent 0249ab5 commit 8ff5368

2 files changed

Lines changed: 23 additions & 219 deletions

File tree

scripts/test.py

Lines changed: 0 additions & 205 deletions
This file was deleted.

scripts/update_docs.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ def convert_md(md_text: str) -> str:
8686

8787
return replaced_md
8888

89-
def lim(s): # literal if multi-line
90-
if '\n' in s:
91-
return ruamel.yaml.scalarstring.LiteralScalarString(s)
92-
return s
89+
9390

9491
def format_content(pathlist, docs_path):
9592
"""
@@ -146,18 +143,30 @@ def format_content(pathlist, docs_path):
146143
if path.name != "projects.md":
147144
post.metadata["sidebar"] = {"nav": "projects"}
148145

149-
data = {"full_description": lim(post.content)}
146+
data = {"full_description": post.content}
150147
post.metadata.update(data)
151148

152-
clean_metadata = {}
153-
for key, value in post.metadata.items():
154-
if isinstance(value, ruamel.yaml.scalarstring.LiteralScalarString):
155-
clean_metadata[key] = str(value)
156-
else:
157-
clean_metadata[key] = value
149+
# Use ruamel.yaml for proper literal block scalar formatting
150+
yaml = ruamel.yaml.YAML()
151+
yaml.preserve_quotes = True
152+
yaml.width = 4096
153+
154+
# Create the frontmatter manually to ensure literal block scalars
155+
metadata_copy = post.metadata.copy()
156+
157+
# Convert multiline strings to literal scalars
158+
for key, value in metadata_copy.items():
159+
if isinstance(value, str) and '\n' in value:
160+
metadata_copy[key] = ruamel.yaml.scalarstring.LiteralScalarString(value)
161+
162+
# Manually construct the frontmatter
163+
from io import StringIO
164+
stream = StringIO()
165+
yaml.dump(metadata_copy, stream)
166+
yaml_content = stream.getvalue()
158167

159-
# Serialize back to frontmatter+content
160-
formatted_content = frontmatter.dumps(clean_post)
168+
# Build the full content with frontmatter
169+
formatted_content = f"---\n{yaml_content}---\n{post.content}"
161170

162171
# Convert Markdown image embeds → HTML and copy assets
163172
converted_content = convert_md_images_to_html(
@@ -193,4 +202,4 @@ def main():
193202
format_content(projects_extended_project_pathlist, docs_posts_dir)
194203

195204
if __name__ == "__main__":
196-
main()
205+
main()

0 commit comments

Comments
 (0)