summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog31
-rw-r--r--README.md84
-rw-r--r--requirements.txt3
-rw-r--r--src/pyssg/page.py4
-rw-r--r--src/pyssg/parser.py19
-rw-r--r--src/pyssg/pyssg.py38
6 files changed, 122 insertions, 57 deletions
diff --git a/ChangeLog b/ChangeLog
index edde04e..de1c8f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,37 @@
CHANGES
=======
+v0.5.8
+------
+
+* add new extensions
+
+v0.5.7
+------
+
+* fix bug on prev/next objects of page
+
+v0.5.6
+------
+
+* add config to read first pyssgrc and then to the xdg directory
+* fix bug on image\_url
+
+v0.5.5
+------
+
+* fix another bug
+
+v0.5.4
+------
+
+* fix bug
+
+v0.5.3
+------
+
+* refactor code and add image\_url parsing
+
v0.5.2
------
diff --git a/README.md b/README.md
index ff20b5b..d4d1f12 100644
--- a/README.md
+++ b/README.md
@@ -9,15 +9,16 @@ I'm writing this in *pYtHoN* (thought about doing it in Go, but I'm most comfort
**This is still a WIP. Still doesn't build `sitemap.xml` or `rss.xml` files.**
- [x] Build static site parsing `markdown` files ( `*.md` -> `*.html`)
- - [x] ~~Using plain `*.html` files for templates.~~ Changed to Jinja templates.
- - [x] Would like to change to something more flexible and easier to manage ([`jinja`](https://jinja.palletsprojects.com/en/3.0.x/), for example).
- - [x] Preserves hand-made `*.html` files.
- - [x] Tag functionality.
- - [ ] Open Graph (and similar) support.
+ - [x] ~~Using plain `*.html` files for templates.~~ Changed to Jinja templates.
+ - [x] Would like to change to something more flexible and easier to manage ([`jinja`](https://jinja.palletsprojects.com/en/3.0.x/), for example).
+ - [x] Preserves hand-made `*.html` files.
+ - [x] Tag functionality.
+ - [ ] Open Graph (and similar) support. (Technically, this works if you add the correct metadata to the `*.md` files and use the variables available for Jinja)
- [x] Build `sitemap.xml` file.
- [x] Build `rss.xml` file.
+ - [ ] Join the `static_url` to all relative URLs found to comply with the [RSS 2.0 spec](https://validator.w3.org/feed/docs/rss2.html) (this would be added to the parsed HTML text extracted from the MD files, so it would be available to the created `*.html` and `*.xml` files). Note that depending on the reader, it will append the URL specified in the RSS file or use the [`xml:base`](https://www.rssboard.org/news/151/relative-links) specified ([newsboat](https://newsboat.org/) parses `xml:base`).
- [x] Only build page if `*.md` is new or updated.
- - [ ] Extend this to tag pages and index (right now all tags and index is built no matter if no new/updated file is present).
+ - [ ] Extend this to tag pages and index (right now all tags and index is built no matter if no new/updated file is present).
- [x] Configuration file as an alternative to using command line flags (configuration file options are prioritized).
### Markdown features
@@ -30,6 +31,9 @@ This program uses the base [`markdown` syntax](https://daringfireball.net/projec
- SmartyPants.
- Table of Contents.
- WikiLinks.
+- [yafg - Yet Another Figure Generator](https://git.sr.ht/~ferruck/yafg)
+- [markdown.highlight](https://github.com/ribalba/markdown.highlight)
+- [Markdown Checklist](https://github.com/FND/markdown-checklist)
## Installation
@@ -72,39 +76,39 @@ For more options/flags just checkout `pyssg -h`.
Here is the list of variables that you can use specific Jinja templates with a short description. Note that all urls are without the trailing slash `/`.
- `config` (`Configuration`) (all): configuration object containing general/global attributes, the useful ones being:
- - `title` (`str`): title of the website.
- - `url` (`str`): base url of the website.
- - `static_url` (`str`): base static url where all static files are located, mostly needed for correct rss feed generator when using a `base` tag and using relative links to files. For more, see [<base>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base).
- - `default_image_url` (`str`): as defined in `DEFAULT_IMAGE_URL` configuration option.
- - `version` (`str`): version in numeric form, i.e. `0.5.0`.
- - `run_date` (`str`): date when the program was run, with format required for rss.
+ - `title` (`str`): title of the website.
+ - `url` (`str`): base url of the website.
+ - `static_url` (`str`): base static url where all static files are located, mostly needed for correct rss feed generator when using a `base` tag and using relative links to files. For more, see [<base>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base).
+ - `default_image_url` (`str`): as defined in `DEFAULT_IMAGE_URL` configuration option.
+ - `version` (`str`): version in numeric form, i.e. `0.5.0`.
+ - `run_date` (`str`): date when the program was run, with format required for rss.
- Pages:
- - `all_pages` (`list(Page)`) (all): list of all the pages, sorted by creation time, reversed.
- - `page` (`Page`) (`page.html`): page object that contains the following attributes:
- - `title` (`str`): title of the page.
- - `author` (`str`): author of the page.
- - `content` (`str`): actual content of the page.
- - `cdatetime` (`str`): creation datetime object of the page.
- - `cdate` (`str`): formatted `cdatetime` as the configuration option `DATE_FORMAT`.
- - `cdate_list` (`str`): formatted `cdatetime` as the configuration option `LIST_DATE_FORMAT`.
- - `cdate_list_sep` (`str`): formatted `cdatetime` as the configuration option `LIST_SEP_DATE_FORMAT`.
- - `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.
- - `mdate` (`str`): formatted `mdatetime` as the configuration option `DATE_FORMAT`. Defaults to None.
- - `mdate_list` (`str`): formatted `mdatetime` as the configuration option `LIST_DATE_FORMAT`.
- - `mdate_list_sep` (`str`): formatted `mdatetime` as the configuration option `LIST_SEP_DATE_FORMAT`.
- - `mdate_rss` (`str`): formatted `mdatetime` as required by rss.
- - `mdate_sitemap` (`str`): formatted `mdatetime` as required by sitemap.
- - `summary` (`str`): summary of the page, as specified in the `*.md` file.
- - `lang` (`str`): page language, used for the general `html` tag `lang` attribute.
- - `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.
- - `url` (`str`): url of the page, this already includes the `config.url`.
- - `image_url` (`str`): image url of the page, this already includes the `config.static_url`. Defaults to the `DEFAULT_IMAGE_URL` configuration option.
- - `next/previous` (`Page`): reference to the next or previous page object (containing all these attributes). Defaults to None
- - `og` (`dict(str, str)`): dict for object graph metadata.
- - `meta` (`dict(str, list(str))`): meta dict as obtained from python-markdown, in case you use a meta tag not yet supported, it will be available there.
+ - `all_pages` (`list(Page)`) (all): list of all the pages, sorted by creation time, reversed.
+ - `page` (`Page`) (`page.html`): page object that contains the following attributes:
+ - `title` (`str`): title of the page.
+ - `author` (`str`): author of the page.
+ - `content` (`str`): actual content of the page.
+ - `cdatetime` (`str`): creation datetime object of the page.
+ - `cdate` (`str`): formatted `cdatetime` as the configuration option `DATE_FORMAT`.
+ - `cdate_list` (`str`): formatted `cdatetime` as the configuration option `LIST_DATE_FORMAT`.
+ - `cdate_list_sep` (`str`): formatted `cdatetime` as the configuration option `LIST_SEP_DATE_FORMAT`.
+ - `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.
+ - `mdate` (`str`): formatted `mdatetime` as the configuration option `DATE_FORMAT`. Defaults to None.
+ - `mdate_list` (`str`): formatted `mdatetime` as the configuration option `LIST_DATE_FORMAT`.
+ - `mdate_list_sep` (`str`): formatted `mdatetime` as the configuration option `LIST_SEP_DATE_FORMAT`.
+ - `mdate_rss` (`str`): formatted `mdatetime` as required by rss.
+ - `mdate_sitemap` (`str`): formatted `mdatetime` as required by sitemap.
+ - `summary` (`str`): summary of the page, as specified in the `*.md` file.
+ - `lang` (`str`): page language, used for the general `html` tag `lang` attribute.
+ - `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.
+ - `url` (`str`): url of the page, this already includes the `config.url`.
+ - `image_url` (`str`): image url of the page, this already includes the `config.static_url`. Defaults to the `DEFAULT_IMAGE_URL` configuration option.
+ - `next/previous` (`Page`): reference to the next or previous page object (containing all these attributes). Defaults to None
+ - `og` (`dict(str, str)`): dict for object graph metadata.
+ - `meta` (`dict(str, list(str))`): meta dict as obtained from python-markdown, in case you use a meta tag not yet supported, it will be available there.
- Tags:
- - `tag` (`tuple(str)`) (`tag.html`): tuple of name and url of the current tag.
- - `tag_pages` (`list(Page)`) (`tag.html`): similar to `all_pages` but contains all the pages for the current tag.
- - `all_tags` (`list(tuple(str))`) (all): similar to `page.tags` but contains all the tags.
+ - `tag` (`tuple(str)`) (`tag.html`): tuple of name and url of the current tag.
+ - `tag_pages` (`list(Page)`) (`tag.html`): similar to `all_pages` but contains all the pages for the current tag.
+ - `all_tags` (`list(tuple(str))`) (all): similar to `page.tags` but contains all the tags.
diff --git a/requirements.txt b/requirements.txt
index 248a5ba..c62a881 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,5 @@
markdown==3.3.4
jinja2==3.0.1
+yafg==0.3
+MarkdownHighlight==0.1.3
+markdown-checklist==0.4.3
diff --git a/src/pyssg/page.py b/src/pyssg/page.py
index 43acb05..6b83d39 100644
--- a/src/pyssg/page.py
+++ b/src/pyssg/page.py
@@ -98,10 +98,10 @@ class Page:
try:
self.image_url = \
- f'{self.config.base_static_url}/{self.meta["image_url"]}'
+ f'{self.config.static_url}/{self.meta["image_url"][0]}'
except KeyError:
self.image_url = \
- f'{self.config.base_static_url}/{self.config.default_image_url}'
+ f'{self.config.static_url}/{self.config.default_image_url}'
# if contains open graph elements
try:
diff --git a/src/pyssg/parser.py b/src/pyssg/parser.py
index d75c923..f2d23eb 100644
--- a/src/pyssg/parser.py
+++ b/src/pyssg/parser.py
@@ -67,14 +67,15 @@ class MDParser:
self.all_tags.sort(key=itemgetter(0))
self.updated_pages.sort(reverse=True)
self.all_pages.sort(reverse=True)
- # TODO: fix this in case it doesn't work lol
- for i, p in enumerate(self.all_pages):
- try:
- prev_page: Page = self.all_pages[i - 1]
- p.previous = prev_page
- except IndexError: pass
- try:
- next_page: Page = self.all_pages[i + 1]
+ pages_amount: int = len(self.all_pages)
+ # note that prev and next are switched because of the reverse rodering
+ # of all_pages
+ for i, p in enumerate(self.all_pages):
+ if i != 0:
+ next_page: Page = self.all_pages[i - 1]
p.next = next_page
- except IndexError: pass
+
+ if i != pages_amount - 1:
+ prev_page: Page = self.all_pages[i + 1]
+ p.previous = prev_page
diff --git a/src/pyssg/pyssg.py b/src/pyssg/pyssg.py
index 75f0fe4..8e54f71 100644
--- a/src/pyssg/pyssg.py
+++ b/src/pyssg/pyssg.py
@@ -1,17 +1,19 @@
import os
import shutil
+from importlib.resources import path
from argparse import ArgumentParser, Namespace
from typing import Union
+
from jinja2 import Environment, FileSystemLoader
from markdown import Markdown
-from importlib.resources import path
+from yafg import YafgExtension
+from MarkdownHighlight.highlight import HighlightExtension
+from markdown_checklist.extension import ChecklistExtension
from .configuration import Configuration
from .database import Database
from .builder import Builder
from .page import Page
-from .rss import RSSBuilder
-from .sitemap import SitemapBuilder
def get_options() -> Namespace:
@@ -29,6 +31,7 @@ def get_options() -> Namespace:
default='$XDG_CONFIG_HOME/pyssg/pyssgrc',
type=str,
help='''config file (path) to read from; defaults to
+ 'pyssgrc' first, then
'$XDG_CONFIG_HOME/pyssg/pyssgrc' ''')
parser.add_argument('-s', '--src',
default='src',
@@ -101,7 +104,13 @@ def main() -> None:
conf_path: str = opts['config']
conf_path = os.path.expandvars(conf_path)
- config: Configuration = Configuration(conf_path)
+
+ config: Configuration = None
+ if os.path.exists('pyssgrc'):
+ config = Configuration('pyssgrc')
+ else:
+ config = Configuration(conf_path)
+
config.read()
config.fill_missing(opts)
@@ -143,8 +152,25 @@ def main() -> None:
trim_blocks=True,
lstrip_blocks=True)
- md: Markdown = Markdown(extensions=['extra', 'meta', 'sane_lists',
- 'smarty', 'toc', 'wikilinks'],
+
+ # md extensions
+ exts: list = ['extra',
+ 'meta',
+ 'sane_lists',
+ 'smarty',
+ 'toc',
+ 'wikilinks',
+ # stripTitle generates an error when True,
+ # if there is no title attr
+ YafgExtension(stripTitle=False,
+ figureClass="",
+ figcaptionClass="",
+ figureNumbering=False,
+ figureNumberClass="number",
+ figureNumberText="Figure"),
+ HighlightExtension(),
+ ChecklistExtension()]
+ md: Markdown = Markdown(extensions=exts,
output_format='html5')
builder: Builder = Builder(config, env, db, md)
builder.build()