mirror of
https://github.com/alvierahman90/gronk.git
synced 2025-10-13 16:04:29 +00:00
Compare commits
8 Commits
blog
...
41cadb0354
Author | SHA1 | Date | |
---|---|---|---|
41cadb0354
|
|||
a7fc67ee00
|
|||
f94fd769cc
|
|||
2b2cdcef79
|
|||
aa159369fd
|
|||
7bee57bcd5
|
|||
8300c4ba45
|
|||
390f5a789f
|
@@ -104,6 +104,12 @@ mjx-container {
|
||||
|
||||
p.metadata { margin: 0 }
|
||||
|
||||
.blog_inline_post {
|
||||
border-left: 1em solid var(--fg-lc);
|
||||
padding: 0 1em 0 1em;
|
||||
margin-bottom: 5em;
|
||||
}
|
||||
|
||||
@media (max-width: 80em) {
|
||||
/* CSS that should be displayed if width is equal to or less than 60em goes here */
|
||||
#contentWrapper { flex-direction: column }
|
||||
|
39
gronk.py
39
gronk.py
@@ -14,6 +14,7 @@ import time
|
||||
import magic
|
||||
import regex as re
|
||||
import pprint
|
||||
from datetime import datetime as dt
|
||||
|
||||
import frontmatter
|
||||
import jinja2
|
||||
@@ -59,7 +60,6 @@ class FileMap:
|
||||
|
||||
def get_base_url(self):
|
||||
props = self.get(self.input_dir.joinpath('readme.md'))
|
||||
print(props)
|
||||
return props['base_url']
|
||||
|
||||
@staticmethod
|
||||
@@ -246,6 +246,15 @@ class FileMap:
|
||||
return d
|
||||
|
||||
|
||||
def rfc822_date_sorter_key(date):
|
||||
if date is None:
|
||||
ret = 0
|
||||
else:
|
||||
ret = int(dt.strptime(date, '%a, %d %b %Y %H:%M:%S %z').timestamp())
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def update_required(src_filepath, output_filepath):
|
||||
"""
|
||||
check if file requires an update,
|
||||
@@ -531,6 +540,22 @@ def main(args):
|
||||
}
|
||||
posts.append(post)
|
||||
|
||||
posts.sort(
|
||||
key=lambda p: rfc822_date_sorter_key(p.get('pub_date')),
|
||||
reverse=True
|
||||
)
|
||||
|
||||
# render rss feed
|
||||
rss = JINJA_TEMPLATE_BLOG_FEED.render(
|
||||
title=root_properties.get('title', ''),
|
||||
description=root_properties.get('content', ''),
|
||||
base_url=FILEMAP.get_base_url(),
|
||||
link=f"{FILEMAP.get_base_url()}{root_properties['dst_path']['web']}",
|
||||
language='en-GB',
|
||||
posts=posts,
|
||||
)
|
||||
root_properties['dst_path']['raw'].joinpath('feed.xml').write_text(rss)
|
||||
|
||||
#pprint.pprint(root_properties)
|
||||
# render index
|
||||
html = (JINJA_TEMPLATE_BLOGINDEX if root_properties['blog'] else JINJA_TEMPLATE_INDEX).render(
|
||||
@@ -549,18 +574,6 @@ def main(args):
|
||||
)
|
||||
root_properties['dst_path']['raw'].joinpath('index.html').write_text(html)
|
||||
|
||||
# render rss feed if blog
|
||||
if root_properties['blog']:
|
||||
rss = JINJA_TEMPLATE_BLOG_FEED.render(
|
||||
title=root_properties.get('title', ''),
|
||||
description=root_properties.get('content', ''),
|
||||
base_url=FILEMAP.get_base_url(),
|
||||
link=f"{FILEMAP.get_base_url()}{root_properties['dst_path']['web']}",
|
||||
language='en-GB',
|
||||
posts=posts,
|
||||
)
|
||||
root_properties['dst_path']['raw'].joinpath('feed.xml').write_text(rss)
|
||||
|
||||
# render each file
|
||||
for file in files:
|
||||
render_file(root.joinpath(file))
|
||||
|
12
readme.md
12
readme.md
@@ -74,7 +74,7 @@ gronk reads the following YAML [frontmatter](https://jekyllrb.com/docs/front-mat
|
||||
| variable | description |
|
||||
|------------------|---------------------------------------------------------------------------------------|
|
||||
| `author` | The person(s) who wrote the article |
|
||||
| `pub_date` | set the publish date of an article/post/note |
|
||||
| `pub_date` | (for blog mode) set the publish date of an article/post/note (MUST be RFC822 format) |
|
||||
| `tags` | A YAML list of tags which the article relates to - this is used for browsing and also |
|
||||
| `title` | The title of the article |
|
||||
| `uuid` | A unique identifier used for permalinks. |
|
||||
@@ -88,6 +88,16 @@ This can be done by setting the `blog` variable to `true` in the `readme.md` [cu
|
||||
|
||||
Notes under this directory will be published to a blog, whose feed is accesible at `https://notes.alv.cx/notes/<directory..>/feed.xml`.
|
||||
|
||||
When blog mode is enabled, it is required that the `base_url` property is set in the top level `readme.md` file.
|
||||
Note that there should be no trailing slash.
|
||||
If a `readme.md` file does not exist, then an empty one can be created:
|
||||
|
||||
```md
|
||||
---
|
||||
base_url: https://notes.alv.cx
|
||||
---
|
||||
```
|
||||
|
||||
|
||||
## Permalinks
|
||||
|
||||
|
@@ -31,7 +31,10 @@
|
||||
<pre>{{ license }}</pre>
|
||||
</details>
|
||||
{% endif %}
|
||||
{% if not content %}
|
||||
<h1>{{ title }}</h1>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% if not content_after_search %}
|
||||
{{ content|safe }}
|
||||
@@ -44,7 +47,7 @@
|
||||
{% if automatic_index %}
|
||||
<details>
|
||||
<summary>
|
||||
<h2> List of posts </h2>
|
||||
<h4> List of posts </h4>
|
||||
</summary>
|
||||
{% if search_bar %}
|
||||
<div id="searchWrapper">
|
||||
@@ -68,7 +71,9 @@
|
||||
{{ content|safe }}
|
||||
|
||||
{% for post in posts %}
|
||||
<div class="blog_inline_post">
|
||||
{{ post['description']|safe }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
{% if not content %}
|
||||
<h1>{{ title }}</h1>
|
||||
{% endif %}
|
||||
|
||||
{% if not content_after_search %}
|
||||
{{ content|safe }}
|
||||
|
Reference in New Issue
Block a user