summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2023-08-29 00:27:19 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2023-08-29 00:27:19 -0600
commit36c5ee34f7bbc903fa97451dfd42b2b915ea83ab (patch)
tree1b6b3da5e7925a661a72554c7426cdcf6e13226c
parent2b858a5f1b62ae76dddc1a0c0406cf1c20d5bc45 (diff)
feat: add essential templates, refactor
-rw-r--r--src/pyssg/builder.py6
-rw-r--r--src/pyssg/md/__init__.py0
-rw-r--r--src/pyssg/md/page.py (renamed from src/pyssg/page.py)2
-rw-r--r--src/pyssg/md/parser.py (renamed from src/pyssg/md_parser.py)4
-rw-r--r--src/pyssg/plt/base.html10
-rw-r--r--src/pyssg/plt/default.yaml1
-rw-r--r--src/pyssg/plt/index.html39
-rw-r--r--src/pyssg/plt/page.html38
-rw-r--r--src/pyssg/plt/page_index.html15
-rw-r--r--src/pyssg/plt/page_list.html15
-rw-r--r--src/pyssg/plt/tag.html26
-rw-r--r--src/pyssg/plt/tag_index.html11
-rw-r--r--src/pyssg/plt/tag_list.html7
-rw-r--r--src/pyssg/pyssg.py12
14 files changed, 95 insertions, 91 deletions
diff --git a/src/pyssg/builder.py b/src/pyssg/builder.py
index 1eec345..0cb1728 100644
--- a/src/pyssg/builder.py
+++ b/src/pyssg/builder.py
@@ -1,15 +1,14 @@
import os
import sys
from copy import deepcopy
-from operator import itemgetter
from logging import Logger, getLogger
from jinja2 import Environment, Template, FileSystemLoader as FSLoader
from pyssg.utils import get_file_list, get_dir_structure, create_dir, copy_file
from pyssg.db.database import Database
-from pyssg.md_parser import MDParser
-from pyssg.page import Page
+from pyssg.md.parser import MDParser
+from pyssg.md.page import Page
log: Logger = getLogger(__name__)
@@ -28,7 +27,6 @@ class Builder:
log.error('dir path "%s" cannot be absolute', self.dir_cfg['dir'])
sys.exit(1)
-
if self.dir_cfg['dir'].strip() == '/':
log.debug('dir path is "/", copying src/dst directly')
self.dir_cfg['src'] = self.config['path']['src']
diff --git a/src/pyssg/md/__init__.py b/src/pyssg/md/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/pyssg/md/__init__.py
diff --git a/src/pyssg/page.py b/src/pyssg/md/page.py
index ae88a67..6a393d1 100644
--- a/src/pyssg/page.py
+++ b/src/pyssg/md/page.py
@@ -52,8 +52,6 @@ class Page:
var, or_else)
return or_else
- # these date/cdate/mdate might be a bit overcomplicated
-
def date(self, ts: float, format: str) -> str:
dt: datetime = datetime.fromtimestamp(ts, tz=timezone.utc)
diff --git a/src/pyssg/md_parser.py b/src/pyssg/md/parser.py
index 0c0dd5b..34a8922 100644
--- a/src/pyssg/md_parser.py
+++ b/src/pyssg/md/parser.py
@@ -1,7 +1,5 @@
import os
-from operator import itemgetter
from logging import Logger, getLogger
-import sys
from typing import Any
from markdown import Markdown
@@ -11,7 +9,7 @@ from markdown_checklist.extension import ChecklistExtension
from markdown.extensions.toc import TocExtension
from pyssg.db.database import Database
-from pyssg.page import Page
+from pyssg.md.page import Page
from pyssg.utils import get_file_stats
log: Logger = getLogger(__name__)
diff --git a/src/pyssg/plt/base.html b/src/pyssg/plt/base.html
new file mode 100644
index 0000000..5207d0f
--- /dev/null
+++ b/src/pyssg/plt/base.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ {%block head_title%}{%endblock head_title%}
+ </head>
+ <body>
+ {%block body_content%}{%endblock body_content%}
+ </body>
+</html>
diff --git a/src/pyssg/plt/default.yaml b/src/pyssg/plt/default.yaml
index b458b75..cca0fbc 100644
--- a/src/pyssg/plt/default.yaml
+++ b/src/pyssg/plt/default.yaml
@@ -21,6 +21,7 @@ info:
dir: "/"
plt: "page.html"
tags: False
+tags_prefix: ''
index: False
rss: False
sitemap: False
diff --git a/src/pyssg/plt/index.html b/src/pyssg/plt/index.html
index 23d890a..4409ba4 100644
--- a/src/pyssg/plt/index.html
+++ b/src/pyssg/plt/index.html
@@ -1,32 +1,9 @@
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="utf-8">
- <base href="{{config['url']['static']}}">
- <title>Index -- {{config['title']}}</title>
- </head>
- <body>
- <h1>Index -- {{config['title']}}</h1>
- <p>Some text here.</p>
-
- <p>Tags:
- {%for t in all_tags%}
- <a href="{{t[1]}}">{{t[0]}}</a>{{", " if not loop.last else ""}}
- {%endfor%}
- </p>
+{%extends "base.html"%}
+{%block head_title%}
+ <title>Index -- {{config['title']}}</title>
+{%endblock head_title%}
- <h2>Articles</h2>
- <ul>
- {%for p in all_pages%}
- {%if loop.previtem%}
- {%if loop.previtem.date(loop.previtem.cts, 'list_sep_date') != p.date(p.cts, 'list_sep_date')%}
- <h3>{{p.date(p.cts, 'list_sep_date')}}</h3>
- {%endif%}
- {%else%}
- <h3>{{p.date(p.cts, 'list_sep_date')}}</h3>
- {%endif%}
- <li>{{p.date(p.cts, 'list_date')}} - <a href="{{p.url}}">{{p.title}}</a></li>
- {%endfor%}
- </ul>
- </body>
-</html>
+{%block body_content%}
+ <h1>Index -- {{config['title']}}</h1>
+ {{page.content}}
+{%endblock body_content%}
diff --git a/src/pyssg/plt/page.html b/src/pyssg/plt/page.html
index b61ad03..395b0f0 100644
--- a/src/pyssg/plt/page.html
+++ b/src/pyssg/plt/page.html
@@ -1,25 +1,19 @@
-<!DOCTYPE html>
-<html lang="{{page.lang}}">
- <head>
- <meta charset="utf-8">
- <base href="{{config['url']['static']}}">
- <title>{{page.title}} -- {{config['title']}}</title>
- </head>
- <body>
- <h1>{{page.title}}</h1>
- <p>By {{page.author}}</p>
- <p>Created: {{page.date(page.cts, 'date')}}</p>
- {%if page.mtimestamp != 0.0%}
- <p>Modified: {{page.date(page.mts, 'date')}}</p>
- {%endif%}
+{%extends "base.html"%}
+{%block head_title%}
+ <title>{{page.title}} -- {{config['title']}}</title>
+{%endblock head_title%}
- {{page.content}}
+{%block body_content%}
+ <h1>{{page.title}} -- {{config['title']}}</h1>
- <p>Tags:
- {%for t in page.tags%}
- <a href="{{t[1]}}">{{t[0]}}</a>{{", " if not loop.last else ""}}
- {%endfor%}
- </p>
- </body>
-</html>
+ <p>By {{page.author}}</p>
+ <p>Created: {{page.date(page.cts, 'date')}}</p>
+ {%if page.mtimestamp != 0.0%}
+ <p>Modified: {{page.date(page.mts, 'date')}}</p>
+ {%endif%}
+ {{page.content}}
+
+ {%import "tag_list.html" as tag_list%}
+ {{tag_list.print(page.tags)}}
+{%endblock body_content%}
diff --git a/src/pyssg/plt/page_index.html b/src/pyssg/plt/page_index.html
new file mode 100644
index 0000000..70639b2
--- /dev/null
+++ b/src/pyssg/plt/page_index.html
@@ -0,0 +1,15 @@
+{%extends "base.html"%}
+{%block head_title%}
+ <title>Index -- {{config['title']}}</title>
+{%endblock head_title%}
+
+{%block body_content%}
+ <h1>Index -- {{config['title']}}</h1>
+ {{page.content}}
+
+ {%import "tag_list.html" as tag_list%}
+ {{tag_list.print(all_tags)}}
+
+ {%import "page_list.html" as page_list%}
+ {{page_list.print("Articles", all_pages)}}
+{%endblock body_content%}
diff --git a/src/pyssg/plt/page_list.html b/src/pyssg/plt/page_list.html
new file mode 100644
index 0000000..93faf43
--- /dev/null
+++ b/src/pyssg/plt/page_list.html
@@ -0,0 +1,15 @@
+{%macro print(name, pages)%}
+ <h2>{{name}}</h2>
+ <ul>
+ {%for p in pages%}
+ {%if loop.previtem%}
+ {%if loop.previtem.date(loop.previtem.cts, 'list_sep_date') != p.date(p.cts, 'list_sep_date')%}
+ <h3>{{p.date(p.cts, 'list_sep_date')}}</h3>
+ {%endif%}
+ {%else%}
+ <h3>{{p.date(p.cts, 'list_sep_date')}}</h3>
+ {%endif%}
+ <li>{{p.date(p.cts, 'list_date')}} - <a href="/{{p.name}}">{{p.title}}</a></li>
+ {%endfor%}
+ </ul>
+{%endmacro%}
diff --git a/src/pyssg/plt/tag.html b/src/pyssg/plt/tag.html
deleted file mode 100644
index bf15c0d..0000000
--- a/src/pyssg/plt/tag.html
+++ /dev/null
@@ -1,26 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="utf-8">
- <base href="{{config['url']['static']}}">
- <title>Posts filtered by {{tag[0]}} -- {{config['title']}}</title>
- </head>
- <body>
- <h1>Posts filtered by {{tag[0]}}</h1>
- <p>Some text here.</p>
-
- <h2>Articles</h2>
- <ul>
- {%for p in tag_pages%}
- {%if loop.previtem%}
- {%if loop.previtem.date(loop.previtem.cts, 'list_sep_date') != p.date(p.cts, 'list_sep_date')%}
- <h3>{{p.date(p.cts, 'list_sep_date')}}</h3>
- {%endif%}
- {%else%}
- <h3>{{p.date(p.cts, 'list_sep_date')}}</h3>
- {%endif%}
- <li>{{p.date(p.cts, 'list_date')}} - <a href="{{p.url}}">{{p.title}}</a></li>
- {%endfor%}
- </ul>
- </body>
-</html>
diff --git a/src/pyssg/plt/tag_index.html b/src/pyssg/plt/tag_index.html
new file mode 100644
index 0000000..0d80265
--- /dev/null
+++ b/src/pyssg/plt/tag_index.html
@@ -0,0 +1,11 @@
+{%extends "base.html"%}
+{%block head_title%}
+ <title>Posts filtered by {{tag}} -- {{config['title']}}</title>
+{%endblock head_title%}
+
+{%block body_content%}
+ <h1>Posts filtered by {{tag}}</h1>
+
+ {%import "page_list.html" as page_list%}
+ {{page_list.print("Articles", tag_pages)}}
+{%endblock body_content%}
diff --git a/src/pyssg/plt/tag_list.html b/src/pyssg/plt/tag_list.html
new file mode 100644
index 0000000..ebc864e
--- /dev/null
+++ b/src/pyssg/plt/tag_list.html
@@ -0,0 +1,7 @@
+{%macro print(tags)%}
+ <p>Tags:
+ {%for t in tags-%}
+ <a href="/tags/{{t}}.html">{{t}}</a>{{", " if not loop.last else ""}}
+ {%-endfor%}
+ </p>
+{%endmacro%}
diff --git a/src/pyssg/pyssg.py b/src/pyssg/pyssg.py
index fd136d9..26c94d6 100644
--- a/src/pyssg/pyssg.py
+++ b/src/pyssg/pyssg.py
@@ -54,17 +54,23 @@ def main() -> None:
log.debug('changed logging level to DEBUG')
if args['init']:
- idir: str = os.path.normpath(get_expanded_path(str(args['init'])))
log.info('initializing directory structure and copying templates')
+ idir: str = os.path.normpath(get_expanded_path(str(args['init'])))
+
create_dir(idir)
with rpath('pyssg.plt', 'default.yaml') as p:
copy_file(str(p), os.path.join(idir, 'config.yaml'))
+
create_dir(os.path.join(idir, 'src'))
create_dir(os.path.join(idir, 'dst'))
create_dir(os.path.join(idir, 'plt'))
- files: list[str] = ['index.html',
+ files: list[str] = ['base.html',
+ 'index.html',
+ 'page_index.html',
'page.html',
- 'tag.html',
+ 'page_list.html',
+ 'tag_index.html',
+ 'tag_list.html',
'rss.xml',
'sitemap.xml',
'entry.md']