Skip to content
Snippets Groups Projects
Commit 1e3074bd authored by Nouri Alnahawi's avatar Nouri Alnahawi
Browse files

Merge branch 'feature/markdown-gen-script' into 'dev'

Feature/markdown gen script

See merge request !5
parents e61268d3 d1571aa1
Branches
Tags
2 merge requests!6Draft: Merge Dev into Master,!5Feature/markdown gen script
Pipeline #71721 passed
......@@ -5,19 +5,20 @@ variables:
GIT_SUBMODULE_STRATEGY: recursive
MINDMAP_OUT_PATH: ./layouts/shortcodes/mindmap.html
MINDMAP_IN_PATH: ./mindmap_gen/mindmap.md
MINDMAP_SCRIPT_PATH: ./mindmap_gen/mindmap_gen.py
.job_templae: &script
before_script:
- apk add --update npm nodejs
- apk add --update npm nodejs python3
- npm update
- npm install -D --save autoprefixer
- npm install -D --save postcss-cli
- npm install -D --save markmap-lib
- npm install -D --save markmap-cli
script:
# mindmap_gen/Mindmap.md creation script here!
- npx markmap-cli -o $MINDMAP_OUT_PATH $MINDMAP_IN_PATH
- python3 $MINDMAP_SCRIPT_PATH -d $(pwd)/content # Generate the mindmap md file
- npx markmap-cli -o $MINDMAP_OUT_PATH $MINDMAP_IN_PATH # Convert mindmap md file to html
- sed -i 's/100v/60v/g' $(pwd)/layouts/shortcodes/mindmap.html # Replaces the width and hight of mindmap with suitable values
- hugo --minify --gc
except:
- master
......
......@@ -25,7 +25,7 @@ defined in [`.gitlab-ci.yml`](.gitlab-ci.yml).
To work locally with this project, you'll have to follow the steps below:
1. Fork, clone or download this project
1. Fork, clone or download this project (Make sure to also recursively clone the submodules)
2. [Install][] Hugo extended version
3. Preview your project on local host zsing the command `hugo server`
4. Add or edit content etc.
......
import glob
import re
import os
import argparse
class Entry:
def __init__(self, dir_name, file_name, file_title, ref_count):
self.dir_name = dir_name
self.file_name = file_name
self.file_title = file_title
self.ref_count = ref_count
@staticmethod
def get_root():
return "Cryptographic Migration & Agility"
def get_dir(self):
return self.dir_name
def get_file(self):
return self.file_name
def get_title(self):
return self.file_title
def get_refs(self):
return self.ref_count
class MarkdownParser:
def __init__(self, markdown_dir_path):
self.markdown_dir_path = markdown_dir_path
def find_markdown_files(self):
return glob.glob(self.markdown_dir_path + '/**/*.md', recursive=True)
def generate_mindmap_file(self):
md_files = self.find_markdown_files()
entries = []
# Iterate files and create entries
for md_file in md_files:
dir_name = self.get_md_dir_name(md_file)
file_name = self.get_md_file_name(md_file)
file_title = self.get_md_file_title(md_file)
ref_count = self.get_md_ref_count(md_file)
if ref_count > 0:
entries.append(Entry(dir_name, file_name, file_title, ref_count))
# Write entries to file
f = open("mindmap_gen/mindmap.md", "w", encoding="utf8")
f.write(self.generate_mindmap(entries))
f.close()
def generate_mindmap(self, entries):
prev_dir = ""
mm_str = ""
mm_str += ("- " + entries[0].get_root() + "\n")
for entry in entries:
if entry.get_dir() != "agility" and entry.get_dir() != "migration":
continue
if entry.get_dir() == prev_dir:
if entry.get_dir() == "":
mm_str += (" - " + entry.get_title() + " (Refs: " + str(entry.get_refs()) + ")\n")
else:
mm_str += (" - " + entry.get_title() + " (Refs: " + str(entry.get_refs()) + ")\n")
else:
mm_str += (" - " + entry.get_dir().capitalize() + "\n")
mm_str += (" - " + entry.get_title() + " (Refs: " + str(entry.get_refs()) + ")\n")
prev_dir = entry.get_dir()
return mm_str
def get_md_file_title(self, md_file_path):
with open(md_file_path, 'r', encoding="utf8") as file:
data = file.read()
return re.search("title: \"(.*)\"", data).group(1)
def get_md_file_name(self, md_file_path):
file_name = os.path.basename(md_file_path)
return file_name
def get_md_dir_name(self, md_file_path):
dir_name = os.path.basename(os.path.dirname(md_file_path))
if dir_name == "docs":
dir_name = ""
return dir_name
def get_md_ref_count(self, md_file_path):
ref_regex = "\.\.\/refs#(.+)\)"
file_handle = open(md_file_path, mode='r', encoding ="utf8")
ref_count = 0
for line in file_handle.readlines():
match = re.search(ref_regex, line)
if match is not None:
ref_count += 1
return ref_count
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--directory', help='Path to content directory', required=True)
args = parser.parse_args()
content_dir = args.directory
md_parser = MarkdownParser(content_dir)
md_parser.generate_mindmap_file()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment