feat: add tag listings page

This commit is contained in:
thomasabishop 2025-01-17 17:51:40 +00:00
parent 732398ff65
commit 8baa377c19
5 changed files with 59 additions and 25 deletions

View file

@ -1,8 +1,10 @@
import subprocess
from lib.create_target_dir import create_target_dir
from lib.generate_index_file import generate_index_file
from lib.generate_tag_file import generate_tag_file
from lib.transfer_files import transfer_files
from lib.transform_links import transform_links
from lib.generate_index_file import generate_index_file
SOURCE = "/home/thomas/repos/eolas"
TARGET = "/home/thomas/repos/eolas/neuron"
@ -15,6 +17,7 @@ def main():
transfer_files(f"{TARGET}/{build_id}", SOURCE)
transform_links(f"{TARGET}/{build_id}")
generate_index_file(f"{TARGET}/{build_id}", build_id, SOURCE)
generate_tag_file(f"{TARGET}/{build_id}")
subprocess.run(
[
"node",

View file

@ -52,6 +52,6 @@ def generate_index_file(target_dir, unique_dir_name, source_dir):
except Exception as e:
print(
colored(
f"ERROR Error occurred when transferring files: {str(e)}", "light_red"
f"ERROR Error occurred when generating index file: {str(e)}", "light_red"
)
)

View file

@ -0,0 +1,37 @@
import json
import subprocess
from termcolor import colored
def invoke_eolas_db():
process = subprocess.run(
["eolas-db", "export-tags"],
capture_output=True,
text=True,
)
return json.loads(process.stdout)
def generate_tag_file(target_dir):
try:
print(colored("INFO Creating tag file...", "light_blue"))
tag_file = f"{target_dir}/tags.md"
tag_index = invoke_eolas_db()
print(tag_index["time"])
with open(tag_file, "a") as file:
for tag in tag_index:
file.write(f"[{tag}](./tags#{tag}), ")
file.write("\n\n")
for tag in tag_index:
file.write(f"### {tag} \n\n")
for entry in tag_index[tag]:
file.write(f"- [[{entry}]] \n")
except Exception as e:
print(
colored(
f"ERROR Error occurred when creating tag file: {str(e)}", "light_red"
)
)
# check with open syntax

View file

@ -1,4 +1,3 @@
import glob
import shutil
from termcolor import colored

View file

@ -5,27 +5,22 @@ from termcolor import colored
def process_line(line):
image_rgx = r"!\[.*?\]\((.*?)\)"
internal_link_rgx = r"\[.*?\]\((.*?)\)"
img_links = re.findall(image_rgx, line)
internal_links = re.findall(internal_link_rgx, line)
link_rgx = r"\[.*?\]\((.*?)\)"
links = re.findall(link_rgx, line)
if img_links:
for img_link in img_links:
stripped_img_ref = re.search(r"[^/\\]+$", img_link)
if stripped_img_ref:
stripped_img_ref = stripped_img_ref.group()
new_img_ref = f"static/{stripped_img_ref}"
line = line.replace(f"({img_link})", f"({new_img_ref})")
if internal_links:
for internal_link in internal_links:
if internal_link.endswith('.md') and ('/' in internal_link):
stripped_path = (re.search(r"[^/\\]+$", internal_link))
if stripped_path:
stripped_path = stripped_path.group()
line = line.replace(f"({internal_link})", f"({stripped_path})")
return line
if links:
for link in links:
stripped_path = re.search(r"[^/\\]+$", link)
if stripped_path:
stripped_path = stripped_path.group()
# Handle internal links
if ".md" in stripped_path:
line = line.replace(f"({link})", f"({stripped_path})")
# Handle image links
else:
new_img_path = f"static/{stripped_path}"
line = line.replace(f"({link})", f"({new_img_path})")
return line
def transform_links(target_dir):