From: Georgios Atheridis Date: Fri, 31 Mar 2023 19:33:25 +0000 (+0100) Subject: Add Meta Variables in Markdown X-Git-Url: https://git.atheridis.org/?a=commitdiff_plain;h=17bbf5a9a9f8c6a97c1ae6a800a8f0e01c444f16;p=personal%2Fsigma.git Add Meta Variables in Markdown Markdown files can now define variables in the beginning of the file, these can be used in place of defining them in data.toml --- diff --git a/data.toml b/data.toml index 8ae5419..d46ad06 100644 --- a/data.toml +++ b/data.toml @@ -12,26 +12,26 @@ _DATE_FORMAT = "%Y-%m-%d" _extend = "base.html" _footer = "{% file 'footer.html' %}" _title = "Atheridis' Page" +_web_title = "Atheridis' Page" _owner = "Georgios Atheridis" _email = "georgios@atheridis.org" [index] _name = "Home" _title = "My Blog" -_nav = 0 +_nav = 100 [final] -_nav = 5 +_name = "Final" +_nav = 70 [textfile] -_nav = 20 +_name = "Text" +_nav = 80 [about] -_nav = 10 - -[page_dir.index] -_name = "Page Dir" -_nav = 30 +_name = "About" +_nav = 90 [posts] _extend = "post.html" @@ -43,30 +43,7 @@ _extend = "base.html" _name = "Tags" _nav = 40 - -[posts.example] -_owner = "John Doe" -_email = "john_doe@example.com" -_date = "2023-02-04" -_title = "An example post" -_description = "This is a description for the example post" -_tags = ["example", "post", "sigma"] - -[posts.test] -_date = "2023-02-02" -_title = "Test" -_description = "This is a test" -_tags = ["test", "post"] - -[posts.other] -_title = "Another Post" -_description = "The description of another post" -_tags = ["other", "post", "sigma"] [posts.other._table] name = ["Georgios Atheridis", "John Doe", "Jane Doe"] email = ["georgios@atheridis.org", "johndoe@example.com", "janedoe@example.com"] "phone number" = ["1234567890", "0777777777"] - -[posts.python-code] -_title = "Python Code" -_tags = ["post", "python", "example"] diff --git a/pages/final.md b/pages/final.md index facbd28..4d80127 100644 --- a/pages/final.md +++ b/pages/final.md @@ -1 +1,3 @@ # Is this a markdown file? + +$x$ diff --git a/pages/posts/example.md b/pages/posts/example.md index 5a0ba54..08af75b 100644 --- a/pages/posts/example.md +++ b/pages/posts/example.md @@ -1,3 +1,13 @@ +Title: This is my title +Owner: John Doe +Email: john_doe@example.com +Date: 2023-02-05 +Description: This is a description for the example post +Tags: example + post + sigma + + This *is a header* for === diff --git a/pages/posts/other.md b/pages/posts/other.md index 86cef3c..6216562 100644 --- a/pages/posts/other.md +++ b/pages/posts/other.md @@ -1,7 +1,10 @@ -# {{ self._title }} - -{{ self._description }} +title: Another Post +description: The description of another post +tags: other + post + sigma +### {{ self._description }} This is another file this was posted on: {{ self._date }} diff --git a/pages/posts/python-code.html/_value.md b/pages/posts/python-code.html/_value.md index 8968ece..0bb8dd4 100644 --- a/pages/posts/python-code.html/_value.md +++ b/pages/posts/python-code.html/_value.md @@ -1,6 +1,11 @@ -# Here is some python code inside my page +title: Python Code +tags: post + python + example -

test

+### Here is some python code inside my page + +

test

```python

test

{! self._code !} diff --git a/pages/posts/test.md b/pages/posts/test.md index 74377fc..45f82ae 100644 --- a/pages/posts/test.md +++ b/pages/posts/test.md @@ -1,3 +1,8 @@ -# Testing +title: Test +description: This is a test +tags: test + post -This is a test +# {{ self._description }} + +Some test article is being written here diff --git a/sigma b/sigma index ae4760a..076a777 100755 --- a/sigma +++ b/sigma @@ -40,7 +40,12 @@ regex_execute = re.compile(r"{%\s?file (\"|')(.+)\1\s?%}") def md_to_html(md: str) -> str: - return markdown.markdown(md, extensions=["extra", "sane_lists"]) + return markdown.markdown(md, extensions=["extra", "sane_lists", "meta"]) + +def md_meta(md: str) -> dict: + md_meta = markdown.Markdown(extensions=["meta"]) + md_meta.convert(md) + return md_meta.Meta def get_max_mtime(dir: str) -> float: @@ -125,7 +130,25 @@ def get_value_from_file( return if not os.path.isdir(os.path.join(path, dir_name + dir_ext)): - return + if dir_ext != ".md": + return + with open(os.path.join(path, dir_name + dir_ext), "r") as file_in: + m = md_meta(file_in.read()).get(key[1:]) + if not m: + return + if len(m) == 1: + return m[0] + return m + + try: + with open(os.path.join(path, dir_name + dir_ext, "_value.md"), "r") as file_in: + m = md_meta(file_in.read()).get(key[1:]) + if m: + if len(m) == 1: + return m[0] + return m + except FileNotFoundError: + pass for file in os.listdir(os.path.join(path, dir_name + dir_ext)): file_name, file_ext = os.path.splitext(file) @@ -148,6 +171,8 @@ def get_value(data: dict, namespace: tuple, key: str, interpret_ok=True): return value except FileNotFoundError: pass + except IndexError: + pass value = data.get(key) for namespace_item in namespace: data = data.get(namespace_item, data) @@ -343,6 +368,7 @@ def main(args): create_page_index(data) + builds = [] for root, _, files in os.walk(data["_PAGE_ROOT"]): if root.startswith(("_", ".")): diff --git a/static/main.css b/static/main.css index 58de5f9..2a0dc84 100644 --- a/static/main.css +++ b/static/main.css @@ -1,15 +1,96 @@ +:root { + --background-colour-1: #F2FAFB; + --background-colour-2: #CBE5E9; + --background-colour-3: #CFEEDE; + --foreground-colour-1: #2D3536; + --foreground-colour-2: #408089; + --foreground-colour-3: #9BC7CD; + --primary-colour: #B2A6C4; + --secondary-colour: #A6C4B2; + --tertiary-colour: #C4B2A6; +} + body { - background: #DDDDDD; - color: #333333; - max-width: 900px; - margin: auto; - padding-top: 1rem; + background: radial-gradient(circle, var(--background-colour-3) 0%, var(--background-colour-2) 100%); + color: var(--foreground-colour-1); + max-width: 900px; + margin: auto; + font-family: sans-serif; + min-height: 100%; +} +a { + color: var(--foreground-colour-2); + text-decoration: none; + transition: 0.15s; +} + +a:hover { + color: var(--foreground-colour-1); + text-decoration: none; +} + +.content { + box-shadow: 0em 0.1em 0.3em var(--foreground-colour-1); + border-radius: 0.7em; + background: var(--background-colour-1); + margin: 2rem; + padding: 1.4rem; +} + +header { + display: grid; + grid-template-areas: "p nav"; +} + +header > h1 { + margin: 0; + padding: 0; + display: flex; + align-items: center; } + +nav { + display: flex; + flex-direction: row-reverse; +} + nav a { - padding-left: 1rem; - padding-right: 1rem; + background: var(--foreground-colour-2); + color: var(--background-colour-1); + margin-left: 1rem; + padding: 0.7rem; + padding-top: 0.3rem; + padding-bottom: 0.3rem; + border-radius: 0.5em; + display: flex; + align-items: center; } + nav a:hover { - background: #350; - color: #ddd; + background: var(--foreground-colour-3); + color: var(--foreground-color-1); +} + +article { + margin: 1rem; +} + + +article table { + width: 100%; +} + +article table thead th { + text-align: left; +} + +article table tr:hover td { + background-color: var(--background-colour-2); +} + +article table tr td:nth-child(2), +article table tr td:nth-child(3), +article table tr td:nth-child(3), +article table tr td:nth-child(2) { + white-space: normal; } diff --git a/templates/base.html b/templates/base.html index dc079ad..49c1187 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,14 +1,19 @@ - - {{ self._title }} - - - - {% file 'scripts/build_nav.py' %} -
- {{ self._value }} -
- {{ self._footer }} - + + {{ self._title }} + + + +
+

{{ self._web_title }}

+ {% file 'scripts/build_nav.py' %} +
+
+ {{ self._value }} +
+ + diff --git a/templates/footer.html b/templates/footer.html index 8217545..c21d2ec 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -1,3 +1 @@ - +This is my footer on page diff --git a/templates/post.html b/templates/post.html index 296e3af..33321b4 100644 --- a/templates/post.html +++ b/templates/post.html @@ -1,7 +1,19 @@ {% extend 'base.html' %} -

Here is my article

-

From: {{ self._owner }}

-

Date: {{ self._date }}

+
+

{{ self._title }}

+ + + + + + + + + + + +
From:{{ self._owner }}
Date:{{ self._date }}
+
- {{ self._value }} + {{ self._value }}
diff --git a/templates/scripts/build_posts.py b/templates/scripts/build_posts.py index d441918..cbff49f 100644 --- a/templates/scripts/build_posts.py +++ b/templates/scripts/build_posts.py @@ -11,7 +11,13 @@ for post in posts: if post == "tags": continue post_timestamp.append( - (time.strptime(posts[post]["_date"], data["_DATE_FORMAT"]), post) + ( + time.strptime( + get_value(data, ("posts", post), "_date"), + get_value(data, (), "_DATE_FORMAT"), + ), + post, + ) ) post_timestamp = sorted(post_timestamp, reverse=True) diff --git a/templates/scripts/build_table.py b/templates/scripts/build_table.py index 30dc6f8..ad6a071 100644 --- a/templates/scripts/build_table.py +++ b/templates/scripts/build_table.py @@ -1,4 +1,4 @@ -_value = "%(head)s%(body)s
" +_value = '%(head)s%(body)s
' posts = "" table = get_value(data, namespace, "_table")