Skip to content

Commit 49af31e

Browse files
Merge pull request #52 from DefangLabs/linda-fix-broken-link
Fix date format in blog links
2 parents 6987948 + 7628f6b commit 49af31e

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

app/get_knowledge_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,18 @@ def parse_markdown_file_to_json(file_path):
145145
"id": current_id,
146146
"about": about,
147147
"text": text,
148-
"path": file_path.replace("./.tmp/defang-docs", "").replace(".mdx", "").replace(".md", "")
148+
"path": adjust_knowledge_base_entry_path(file_path) # Adjust path format
149149
})
150150
current_id += 1
151151

152152
# Write the augmented JSON output to ./data/knowledge_base.json
153153
with open(kb_file_path, 'w', encoding='utf-8') as output_file:
154154
json.dump(json_output, output_file, indent=2, ensure_ascii=False)
155155

156+
def adjust_knowledge_base_entry_path(file_path):
157+
""" Adjusts the file path format for storage. """
158+
return re.sub(r'\/(\d{4})-(\d{2})-(\d{2})-', r'/\1/\2/\3/', file_path.replace("./.tmp/defang-docs", "").replace(".mdx", "").replace(".md", ""))
159+
156160
def parse_cli_markdown(file_path):
157161
""" Parses CLI-specific markdown files """
158162
try:

app/test_get_knowledge_base.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import unittest
2+
from get_knowledge_base import adjust_knowledge_base_entry_path
3+
4+
class TestGetKnowledgeBase(unittest.TestCase):
5+
6+
def test_adjust_knowledgebase_entry_path(self):
7+
file_path = "./.tmp/defang-docs/2023-03-15-sample.md"
8+
adjusted_path = adjust_knowledge_base_entry_path(file_path)
9+
self.assertEqual(adjusted_path, "/2023/03/15/sample")
10+
print("Test for adjust_knowledgebase_entry_path passed successfully!")
11+
12+
def test_adjust_knowledgebase_entry_path_no_date(self):
13+
file_path = "./.tmp/defang-docs/sample.mdx"
14+
adjusted_path = adjust_knowledge_base_entry_path(file_path)
15+
self.assertEqual(adjusted_path, "/sample")
16+
print("Test for adjust_knowledgebase_entry_path_no_date passed successfully!")
17+
18+
def test_adjust_knowledgebase_entry_path_no_extension(self):
19+
file_path = "./.tmp/defang-docs/sample"
20+
adjusted_path = adjust_knowledge_base_entry_path(file_path)
21+
self.assertEqual(adjusted_path, "/sample")
22+
print("Test for adjust_knowledgebase_entry_path_no_extension passed successfully!")
23+
24+
def test_adjust_knowledgebase_entry_path_empty(self):
25+
file_path = ""
26+
adjusted_path = adjust_knowledge_base_entry_path(file_path)
27+
self.assertEqual(adjusted_path, "")
28+
print("Test for adjust_knowledgebase_entry_path_empty passed successfully!")
29+
30+
def test_adjust_knowledgebase_entry_path_date_at_end(self):
31+
file_path = "./.tmp/defang-docs/example-file-2023-03-15.md"
32+
adjusted_path = adjust_knowledge_base_entry_path(file_path)
33+
self.assertEqual(adjusted_path, "/example-file-2023-03-15")
34+
print("Test for adjust_knowledgebase_entry_path_date_at_end passed successfully!")
35+
36+
def test_adjust_knowledgebase_entry_path_date_at_middle(self):
37+
file_path = "./.tmp/defang-docs/example-file-2023-03-15-something-else.md"
38+
adjusted_path = adjust_knowledge_base_entry_path(file_path)
39+
self.assertEqual(adjusted_path, "/example-file-2023-03-15-something-else")
40+
print("Test for adjust_knowledgebase_entry_path_date_at_middle passed successfully!")
41+
42+
43+
if __name__ == '__main__':
44+
unittest.main()

0 commit comments

Comments
 (0)