madblog/madblog/config.py

58 lines
1.4 KiB
Python
Raw Normal View History

2022-01-11 20:16:27 +01:00
import os
import yaml
from dataclasses import dataclass
@dataclass
class Config:
title = 'Blog'
description = ''
link = '/'
home_link = '/'
language = 'en-US'
logo = '/img/icon.png'
header = True
2022-06-14 00:32:35 +02:00
content_dir = '.'
2022-01-11 20:16:27 +01:00
categories = None
basedir = os.path.abspath(os.path.dirname(__file__))
templates_dir = os.path.join(basedir, 'templates')
static_dir = os.path.join(basedir, 'static')
default_css_dir = os.path.join(static_dir, 'css')
2022-06-14 10:25:57 +02:00
default_js_dir = os.path.join(static_dir, 'js')
2022-01-11 20:16:27 +01:00
default_fonts_dir = os.path.join(static_dir, 'fonts')
default_img_dir = os.path.join(static_dir, 'img')
config = Config()
def init_config(content_dir='.', config_file='config.yaml'):
cfg = {}
config.content_dir = content_dir
if os.path.isfile(config_file):
with open(config_file, 'r') as f:
cfg = yaml.safe_load(f)
if cfg.get('title'):
config.title = cfg['title']
if cfg.get('description'):
config.description = cfg['description']
if cfg.get('link'):
config.link = cfg['link']
if cfg.get('home_link'):
config.home_link = cfg['home_link']
2022-01-13 22:44:43 +01:00
if cfg.get('logo') is not None:
2022-01-11 20:16:27 +01:00
config.logo = cfg['logo']
if cfg.get('language'):
config.language = cfg['language']
if cfg.get('header') is False:
config.header = False
2022-01-11 20:16:27 +01:00
config.categories = cfg.get('categories', [])
# vim:sw=4:ts=4:et: