diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pyssg/page.py | 4 | ||||
-rw-r--r-- | src/pyssg/parser.py | 19 | ||||
-rw-r--r-- | src/pyssg/pyssg.py | 38 |
3 files changed, 44 insertions, 17 deletions
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() |