summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--pyssg.xyz/plt/blog/index.html8
-rw-r--r--pyssg.xyz/plt/blog/page.html4
-rw-r--r--pyssg.xyz/plt/blog/tag.html8
-rw-r--r--src/pyssg/page.py27
-rw-r--r--src/pyssg/plt/index.html8
-rw-r--r--src/pyssg/plt/page.html4
-rw-r--r--src/pyssg/plt/tag.html8
8 files changed, 45 insertions, 28 deletions
diff --git a/README.md b/README.md
index c12e356..79db720 100644
--- a/README.md
+++ b/README.md
@@ -193,10 +193,12 @@ These variables are exposed to use within the templates. The below list is displ
- `lang` (`str`): page language, used for the general `html` tag `lang` attribute.
- `summary` (`str`): summary of the page, as specified in the `*.md` file.
- `content` (`str`): actual content of the page, this is the `html`.
- - `cdatetime` (`str`): creation datetime object of the page.
+ - `cdatetime` (`datetime.datetime`): creation datetime object of the page.
+ - `cdate` (`method`): method thtat takes the name of the `fmt.FMT` and applies it to the `cdatetime` object.
- `cdate_rss` (`str`): formatted `cdatetime` as required by rss.
- `cdate_sitemap` (`str`): formatted `cdatetime` as required by sitemap.
- - `mdatetime` (`str`): modification datetime object of the page. Defaults to `None`.
+ - `mdatetime` (`datetime.datetime`): modification datetime object of the page. Defaults to `None`.
+ - `mdate` (`method`): method thtat takes the name of the `fmt.FMT` and applies it to the `mdatetime` object.
- `mdate_rss` (`str`): formatted `mdatetime` as required by rss.
- `mdate_sitemap` (`str`): formatted `mdatetime` as required by sitemap.
- `tags` (`list(tuple(str))`): list of tuple of tags of the page, containing the name and the url of the tag, in that order. Defaults to empty list.
diff --git a/pyssg.xyz/plt/blog/index.html b/pyssg.xyz/plt/blog/index.html
index 057cd79..c9b13c2 100644
--- a/pyssg.xyz/plt/blog/index.html
+++ b/pyssg.xyz/plt/blog/index.html
@@ -48,13 +48,13 @@
<ul>
{%for p in all_pages%}
{%if loop.previtem%}
- {%if loop.previtem.cdatetime.strftime(config['fmt']['list_sep_date']) != p.cdatetime.strftime(config['fmt']['list_sep_date'])%}
- <h3>{{p.cdatetime.strftime(config['fmt']['list_sep_date'])}}</h3>
+ {%if loop.previtem.cdate('list_sep_date') != p.cdate('list_sep_date')%}
+ <h3>{{p.cdate('list_sep_date')}}</h3>
{%endif%}
{%else%}
- <h3>{{p.cdatetime.strftime(config['fmt']['list_sep_date'])}}</h3>
+ <h3>{{p.cdate('list_sep_date')}}</h3>
{%endif%}
- <li>{{p.cdatetime.strftime(config['fmt']['list_date'])}} - <a href="{{p.url}}">{{p.title}}</a></li>
+ <li>{{p.cdate('list_date')}} - <a href="{{p.url}}">{{p.title}}</a></li>
{%endfor%}
</ul>
{%endblock body_content%}
diff --git a/pyssg.xyz/plt/blog/page.html b/pyssg.xyz/plt/blog/page.html
index 06746ba..510129b 100644
--- a/pyssg.xyz/plt/blog/page.html
+++ b/pyssg.xyz/plt/blog/page.html
@@ -38,9 +38,9 @@
<h1>{{page.title}}</h1>
<p>By {{', '.join(page.author)}}</p>
- <p>Created: {{page.cdatetime.strftime(config['fmt']['date'])}}</p>
+ <p>Created: {{page.cdate('date')}}</p>
{%if page.mdatetime is not none%}
- <p>Modified: {{page.mdatetime.strftime(config['fmt']['date'])}}</p>
+ <p>Modified: {{page.mdate('date')}}</p>
{%endif%}
{{page.content}}
diff --git a/pyssg.xyz/plt/blog/tag.html b/pyssg.xyz/plt/blog/tag.html
index 5b05d7f..0a26882 100644
--- a/pyssg.xyz/plt/blog/tag.html
+++ b/pyssg.xyz/plt/blog/tag.html
@@ -42,13 +42,13 @@
<ul>
{%for p in tag_pages%}
{%if loop.previtem%}
- {%if loop.previtem.cdatetime.strftime(config['fmt']['list_sep_date']) != p.cdatetime.strftime(config['fmt']['list_sep_date'])%}
- <h3>{{p.cdatetime.strftime(config['fmt']['list_sep_date'])}}</h3>
+ {%if loop.previtem.cdate('list_sep_date') != p.cdate('list_sep_date')%}
+ <h3>{{p.cdate('list_sep_date')}}</h3>
{%endif%}
{%else%}
- <h3>{{p.cdatetime.strftime(config['fmt']['list_sep_date'])}}</h3>
+ <h3>{{p.cdate('list_sep_date')}}</h3>
{%endif%}
- <li>{{p.cdatetime.strftime(config['fmt']['list_date'])}} - <a href="{{p.url}}">{{p.title}}</a></li>
+ <li>{{p.cdate('list_date')}} - <a href="{{p.url}}">{{p.title}}</a></li>
{%endfor%}
</ul>
{%endblock body_content%}
diff --git a/src/pyssg/page.py b/src/pyssg/page.py
index 0161f25..85a6a47 100644
--- a/src/pyssg/page.py
+++ b/src/pyssg/page.py
@@ -59,6 +59,23 @@ class Page:
log.debug('getting metadata "%s" failed, using optional value "%s"', var, or_else)
return or_else
+ def cdate(self, format: str) -> str:
+ if format in self.config['fmt']:
+ return self.cdatetime.strftime(self.config['fmt'][format])
+ else:
+ log.warning('format "%s" not found in config["fmt"], returning empty string', format)
+ return ''
+
+ def mdate(self, format: str) -> str:
+ if self.mdatetime is None:
+ log.warning('no mdatetime found, can\'t return a formatted string')
+ return ''
+ if format in self.config['fmt']:
+ return self.mdatetime.strftime(self.config['fmt'][format]) # type: ignore
+ else:
+ log.warning('format "%s" not found in config["fmt"], returning empty string', format)
+ return ''
+
# parses meta from self.meta, for og, it prioritizes,
# the actual og meta
def parse_metadata(self):
@@ -70,16 +87,14 @@ class Page:
log.debug('parsing timestamp')
self.cdatetime = datetime.fromtimestamp(self.ctimestamp, tz=timezone.utc)
- cdate = lambda x : self.cdatetime.strftime(self.config['fmt'][x])
- self.cdate_rss = cdate('rss_date')
- self.cdate_sitemap = cdate('sitemap_date')
+ self.cdate_rss = self.cdate('rss_date')
+ self.cdate_sitemap = self.cdate('sitemap_date')
if self.mtimestamp != 0.0:
log.debug('parsing modified timestamp')
self.mdatetime = datetime.fromtimestamp(self.mtimestamp, tz=timezone.utc)
- mdate = lambda x : self.mdatetime.strftime(self.config['fmt'][x]) # type: ignore
- self.mdate_rss = mdate('rss_date')
- self.mdate_sitemap = mdate('sitemap_date')
+ self.mdate_rss = self.mdate('rss_date')
+ self.mdate_sitemap = self.mdate('sitemap_date')
else:
log.debug('not parsing modified timestamp, hasn\'t been modified')
diff --git a/src/pyssg/plt/index.html b/src/pyssg/plt/index.html
index c33fd37..7c034bb 100644
--- a/src/pyssg/plt/index.html
+++ b/src/pyssg/plt/index.html
@@ -19,13 +19,13 @@
<ul>
{%for p in all_pages%}
{%if loop.previtem%}
- {%if loop.previtem.cdatetime.strftime(config['fmt']['list_sep_date']) != p.cdatetime.strftime(config['fmt']['list_sep_date'])%}
- <h3>{{p.cdatetime.strftime(config['fmt']['list_sep_date'])}}</h3>
+ {%if loop.previtem.cdate('list_sep_date') != p.cdate('list_sep_date')%}
+ <h3>{{p.cdate('list_sep_date')}}</h3>
{%endif%}
{%else%}
- <h3>{{p.cdatetime.strftime(config['fmt']['list_sep_date'])}}</h3>
+ <h3>{{p.cdate('list_sep_date')}}</h3>
{%endif%}
- <li>{{p.cdatetime.strftime(config['fmt']['list_date'])}} - <a href="{{p.url}}">{{p.title}}</a></li>
+ <li>{{p.cdate('list_date')}} - <a href="{{p.url}}">{{p.title}}</a></li>
{%endfor%}
</ul>
</body>
diff --git a/src/pyssg/plt/page.html b/src/pyssg/plt/page.html
index 08e92f1..93d4da9 100644
--- a/src/pyssg/plt/page.html
+++ b/src/pyssg/plt/page.html
@@ -8,9 +8,9 @@
<body>
<h1>{{page.title}}</h1>
<p>By {{page.author}}</p>
- <p>Created: {{page.cdatetime.strftime(config['fmt']['date'])}}</p>
+ <p>Created: {{page.cdate('date')}}</p>
{%if page.mdatetime is not none%}
- <p>Modified: {{page.mdatetime.strftime(config['fmt']['date'])}}</p>
+ <p>Modified: {{page.mdate('date')}}</p>
{%endif%}
{{page.content}}
diff --git a/src/pyssg/plt/tag.html b/src/pyssg/plt/tag.html
index 2dd7177..aff7982 100644
--- a/src/pyssg/plt/tag.html
+++ b/src/pyssg/plt/tag.html
@@ -13,13 +13,13 @@
<ul>
{%for p in tag_pages%}
{%if loop.previtem%}
- {%if loop.previtem.cdatetime.strftime(config['fmt']['list_sep_date']) != p.cdatetime.strftime(config['fmt']['list_sep_date'])%}
- <h3>{{p.cdatetime.strftime(config['fmt']['list_sep_date'])}}</h3>
+ {%if loop.previtem.cdate('list_sep_date') != p.cdate('list_sep_date')%}
+ <h3>{{p.cdate('list_sep_date')}}</h3>
{%endif%}
{%else%}
- <h3>{{p.cdatetime.strftime(config['fmt']['list_sep_date'])}}</h3>
+ <h3>{{p.cdate('list_sep_date')}}</h3>
{%endif%}
- <li>{{p.cdatetime.strftime(config['fmt']['list_date'])}} - <a href="{{p.url}}">{{p.title}}</a></li>
+ <li>{{p.cdate('list_date')}} - <a href="{{p.url}}">{{p.title}}</a></li>
{%endfor%}
</ul>
</body>