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

View file

@ -52,6 +52,6 @@ def generate_index_file(target_dir, unique_dir_name, source_dir):
except Exception as e: except Exception as e:
print( print(
colored( 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 import shutil
from termcolor import colored from termcolor import colored

View file

@ -5,27 +5,22 @@ from termcolor import colored
def process_line(line): def process_line(line):
image_rgx = r"!\[.*?\]\((.*?)\)" link_rgx = r"\[.*?\]\((.*?)\)"
internal_link_rgx = r"\[.*?\]\((.*?)\)" links = re.findall(link_rgx, line)
img_links = re.findall(image_rgx, line)
internal_links = re.findall(internal_link_rgx, line) if links:
for link in links:
if img_links: stripped_path = re.search(r"[^/\\]+$", link)
for img_link in img_links: if stripped_path:
stripped_img_ref = re.search(r"[^/\\]+$", img_link) stripped_path = stripped_path.group()
if stripped_img_ref: # Handle internal links
stripped_img_ref = stripped_img_ref.group() if ".md" in stripped_path:
new_img_ref = f"static/{stripped_img_ref}" line = line.replace(f"({link})", f"({stripped_path})")
line = line.replace(f"({img_link})", f"({new_img_ref})") # Handle image links
else:
if internal_links: new_img_path = f"static/{stripped_path}"
for internal_link in internal_links: line = line.replace(f"({link})", f"({new_img_path})")
if internal_link.endswith('.md') and ('/' in internal_link): return line
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
def transform_links(target_dir): def transform_links(target_dir):
@ -39,7 +34,7 @@ def transform_links(target_dir):
new_lines = [] new_lines = []
for line in lines: for line in lines:
new_lines.append(process_line(line)) new_lines.append(process_line(line))
if len(new_lines): if len(new_lines):
with open(file_path, "w") as f: with open(file_path, "w") as f:
f.writelines(new_lines) f.writelines(new_lines)
print( print(