From 3531726f2c2fa43e16f86ea7f50ddc74b36e4da3 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 11 Jan 2022 23:38:28 +0100 Subject: [PATCH] docs refactor and minor fixes --- README.md | 51 +++++++++++++++++++++++++++++------------------ madblog/app.py | 6 ++---- madblog/cli.py | 12 +---------- madblog/config.py | 1 - madblog/routes.py | 4 ++-- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index d8853f2..3c75199 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# mdblog +# madblog This project provides a minimal blogging platform based on Markdown files. @@ -17,13 +17,14 @@ $ madness ``` ``` -usage: madblog [-h] [--host HOST] [--port PORT] [--debug] [path] +usage: madblog [-h] [--config CONFIG] [--host HOST] [--port PORT] [--debug] [dir] Serve a Markdown folder as a web blog. The folder should have the following structure: . + -> config.yaml [recommended] -> markdown -> article-1.md -> article-2.md @@ -34,26 +35,39 @@ The folder should have the following structure: -> image-1.png -> image-2.png -> ... - -> css [optional] - -> custom-1.css - -> custom-2.css - -> ... - -> fonts [optional] - -> custom-1.ttf - -> custom-1.css - -> ... - -> templates [optional] - -> index.html [for a custom index template] - -> article.html [for a custom article template] positional arguments: - path Base path for the blog + dir Base path for the blog (default: current directory) options: - -h, --help show this help message and exit - --host HOST Bind host/address - --port PORT Bind port (default: 8000) - --debug Enable debug mode (default: False) + -h, --help show this help message and exit + --config CONFIG Path to a configuration file (default: config.yaml in the blog root directory) + --host HOST Bind host/address + --port PORT Bind port (default: 8000) + --debug Enable debug mode (default: False) +``` + +## Configuration + +The application will look for a `config.yaml` file in the current directory if none was +specified through the `-c` command-line option. The structure is the following: + +```yaml +title: Blog title +description: Blog description +link: https://link.to.your.blog +# Use home_link if you have a different home/portal address +# than your blog, otherwise it's the same as `link` +home_link: https://link.to.home +# Path/URL to the logo (default: /img/icon.png) +logo: /path/or/url/here +# Blog language (for the RSS feed) +language: en-US + +categories: + - category1 + - category2 + - category3 ``` ## Markdown files @@ -100,4 +114,3 @@ $$ ## RSS syndacation RSS feeds for the blog are provided under the `/rss` URL. - diff --git a/madblog/app.py b/madblog/app.py index b1469e0..1580a35 100644 --- a/madblog/app.py +++ b/madblog/app.py @@ -1,13 +1,11 @@ import datetime -import os import re from glob import glob from typing import Optional -from flask import Flask, abort, render_template +from flask import Flask, abort from markdown import markdown -from .config import config from .latex import MarkdownLatex @@ -78,7 +76,7 @@ class BlogApp(Flask): author=re.match(r'(.+?)\s+<([^>]+>)', metadata['author'])[1] if 'author' in metadata else None, author_email=re.match(r'(.+?)\s+<([^>]+)>', metadata['author'])[2] if 'author' in metadata else None, published=(metadata['published'].strftime('%b %d, %Y') - if metadata.get('published') else None), + if metadata.get('published') else None), content=markdown(f.read(), extensions=['fenced_code', 'codehilite', MarkdownLatex()]), skip_header=skip_header ) diff --git a/madblog/cli.py b/madblog/cli.py index 79e7fdc..0dbf347 100644 --- a/madblog/cli.py +++ b/madblog/cli.py @@ -2,6 +2,7 @@ import argparse import os import sys + def get_args(): parser = argparse.ArgumentParser(description='''Serve a Markdown folder as a web blog. @@ -19,17 +20,6 @@ The folder should have the following structure: -> image-1.png -> image-2.png -> ... - -> css [optional] - -> custom-1.css - -> custom-2.css - -> ... - -> fonts [optional] - -> custom-1.ttf - -> custom-1.css - -> ... - -> templates [optional] - -> index.html [for a custom index template] - -> article.html [for a custom article template] ''', formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('dir', nargs='?', default='.', help='Base path for the blog (default: current directory)') diff --git a/madblog/config.py b/madblog/config.py index bd066a7..13853e0 100644 --- a/madblog/config.py +++ b/madblog/config.py @@ -1,6 +1,5 @@ import os import yaml -from typing import Optional from dataclasses import dataclass diff --git a/madblog/routes.py b/madblog/routes.py index 57f7b16..cbcbef4 100644 --- a/madblog/routes.py +++ b/madblog/routes.py @@ -53,7 +53,7 @@ def rss_route(): {title} {link} {description} - {",".join(categories)} + {categories} {link}/img/icon.png {title} @@ -68,7 +68,7 @@ def rss_route(): title=config.title, description=config.description, link=config.link, - categories=config.categories, + categories=','.join(config.categories), language=config.language, last_pub_date=pages[0]['published'].strftime('%a, %d %b %Y %H:%M:%S GMT'), items='\n\n'.join([