From 43a7be95f85fbb572e4d1321c0eefb2682ad4fcf Mon Sep 17 00:00:00 2001 From: Mattia Succurro Date: Sun, 12 Jun 2022 11:10:41 +0200 Subject: [PATCH] Add option to specify a different config file; update README and CHANGELOG --- CHANGELOG.md | 30 ++++++++++++++++++++++++++++++ README.md | 8 ++++++-- app.py | 23 ++++++++++++----------- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39a9ca6..cc6e95d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,35 @@ # What’s New +## 0.6 + ++ Added support for database URLs: you can now specify the URL of the database + in `site.conf` by setting `[database]url`, be it MySQL, PostgreSQL or SQLite. ++ Added experimental math support, with `markdown_katex` library. The math + parsing can be opted out in many ways. ++ Backlinks can now be accessed for each page. ++ Spoiler tags at beginning of line now work. Just for now. ++ Removed `Upload` table. ++ Added `PageLink` table. + +## 0.5 + ++ Removed support for uploads. The `/upload/` endpoint now points to an info + page, and the “Upload image” button and gallery from home page are now gone. ++ `markdown_strikethrough` extension is no more needed. Now there are two new + built-in extensions: `StrikethroughExtension` and `SpoilerExtension` (the + last one is buggy tho). ++ Removed support for magic words (the commands between `{{` `}}`). These + features are now lost: `backto`, `media` and `gallery` (easily replaceable + with simple Markdown). ++ Added app version to site footer. ++ Added client-side drafts (they require JS enabled). + +## 0.4 + + +## 0.3 + + ## 0.2 + Some code refactoring. diff --git a/README.md b/README.md index 9cb1ad9..3864c25 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ suitable as a community or team knowledge base. + Write notes on the go, using Markdown syntax + Any note can have its own URL + Revision history -+ Stored in SQLite databases ++ Stored in SQLite/MySQL databases + Material Icons + Light/dark theme + Works fine even with JavaScript disabled. @@ -19,9 +19,13 @@ suitable as a community or team knowledge base. ## Requirements + **Python** 3.6+. -+ **Flask** web framework. ++ **Flask** web framework (and Flask-Login / Flask-WTF extensions). + **Peewee** ORM. +### Optional requirements + +* **Markdown-KaTeX** if you want to display math inside pages. + ## Caveats + All pages created are, as of now, viewable and editable by anyone, with no diff --git a/app.py b/app.py index 591c97b..0e41efa 100644 --- a/app.py +++ b/app.py @@ -32,10 +32,6 @@ try: from slugify import slugify except ImportError: slugify = None -try: - import markdown_katex -except ImportError: - markdown_katex = None __version__ = '0.6-dev' @@ -48,21 +44,17 @@ FK = ForeignKeyField SLUG_RE = r'[a-z0-9]+(?:-[a-z0-9]+)*' ILINK_RE = r'\]\(/(p/\d+|' + SLUG_RE + ')/?\)' -upload_types = {'jpeg': 1, 'jpg': 1, 'png': 2} -upload_types_rev = {1: 'jpg', 2: 'png'} - -UPLOAD_DIR = APP_BASE_DIR + '/media' -DATABASE_DIR = APP_BASE_DIR + "/database" - #### GENERAL CONFIG #### +CONFIG_FILE = os.environ.get('SALVI_CONF', APP_BASE_DIR + '/site.conf') + DEFAULT_CONF = { ('site', 'title'): 'Salvi', ('database', 'directory'): APP_BASE_DIR + "/database", } _cfp = ConfigParser() -if _cfp.read([APP_BASE_DIR + '/site.conf']): +if _cfp.read([CONFIG_FILE]): @lru_cache(maxsize=50) def _getconf(k1, k2, fallback=None, cast=None): if fallback is None: @@ -80,6 +72,15 @@ else: fallback = DEFAULT_CONF.get((k1, k2)) return fallback +#### OPTIONAL IMPORTS #### + +markdown_katex = None +try: + if _getconf('appearance', 'math') != 'off': + import markdown_katex +except ImportError: + pass + #### misc. helpers #### def _makelist(l):