feat: add tag listings page
This commit is contained in:
parent
732398ff65
commit
8baa377c19
5 changed files with 59 additions and 25 deletions
|
@ -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",
|
||||||
|
|
|
@ -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"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
37
src/lib/generate_tag_file.py
Normal file
37
src/lib/generate_tag_file.py
Normal 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
|
|
@ -1,4 +1,3 @@
|
||||||
import glob
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
|
|
|
@ -5,26 +5,21 @@ 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 img_links:
|
if links:
|
||||||
for img_link in img_links:
|
for link in links:
|
||||||
stripped_img_ref = re.search(r"[^/\\]+$", img_link)
|
stripped_path = re.search(r"[^/\\]+$", 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:
|
if stripped_path:
|
||||||
stripped_path = stripped_path.group()
|
stripped_path = stripped_path.group()
|
||||||
line = line.replace(f"({internal_link})", f"({stripped_path})")
|
# 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
|
return line
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue