configuring site_tools

This commit is contained in:
evilchili 2022-08-02 18:20:45 -07:00
parent dabfcff2d6
commit 00c3d2f52d
8 changed files with 173 additions and 423 deletions

346
deadsands/poetry.lock generated
View File

@ -1,346 +0,0 @@
[[package]]
name = "blinker"
version = "1.5"
description = "Fast, simple object-to-object and broadcast signaling"
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
[[package]]
name = "click"
version = "8.1.3"
description = "Composable command line interface toolkit"
category = "main"
optional = false
python-versions = ">=3.7"
[package.dependencies]
colorama = {version = "*", markers = "platform_system == \"Windows\""}
importlib-metadata = {version = "*", markers = "python_version < \"3.8\""}
[[package]]
name = "colorama"
version = "0.4.5"
description = "Cross-platform colored terminal text."
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
[[package]]
name = "commonmark"
version = "0.9.1"
description = "Python parser for the CommonMark Markdown spec"
category = "main"
optional = false
python-versions = "*"
[package.extras]
test = ["hypothesis (==3.55.3)", "flake8 (==3.7.8)"]
[[package]]
name = "dnd-rolltable"
version = "0.9"
description = 'Generate roll tables using weighted random distributions'
category = "main"
optional = false
python-versions = "^3.7"
develop = false
[package.dependencies]
pyyaml = "latest"
rich = "latest"
typer = "latest"
[package.source]
type = "git"
url = "https://github.com/evilchili/dnd-rolltable"
reference = 'main'
resolved_reference = "3c22594fd1c328dc1470335fb8c2fc8918d0a7e8"
[[package]]
name = "docutils"
version = "0.19"
description = "Docutils -- Python Documentation Utilities"
category = "main"
optional = false
python-versions = ">=3.7"
[[package]]
name = "feedgenerator"
version = "2.0.0"
description = "Standalone version of django.utils.feedgenerator"
category = "main"
optional = false
python-versions = ">=3.6"
[package.dependencies]
pytz = ">=0a"
[[package]]
name = "importlib-metadata"
version = "4.12.0"
description = "Read metadata from Python packages"
category = "main"
optional = false
python-versions = ">=3.7"
[package.dependencies]
typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""}
zipp = ">=0.5"
[package.extras]
docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"]
perf = ["ipython"]
testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.3)", "packaging", "pyfakefs", "flufl.flake8", "pytest-perf (>=0.9.2)", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)", "importlib-resources (>=1.3)"]
[[package]]
name = "invoke"
version = "1.7.1"
description = "Pythonic task execution"
category = "main"
optional = false
python-versions = "*"
[[package]]
name = "jinja2"
version = "3.1.2"
description = "A very fast and expressive template engine."
category = "main"
optional = false
python-versions = ">=3.7"
[package.dependencies]
MarkupSafe = ">=2.0"
[package.extras]
i18n = ["Babel (>=2.7)"]
[[package]]
name = "markdown"
version = "3.4.1"
description = "Python implementation of Markdown."
category = "main"
optional = false
python-versions = ">=3.7"
[package.dependencies]
importlib-metadata = {version = ">=4.4", markers = "python_version < \"3.10\""}
[package.extras]
testing = ["coverage", "pyyaml"]
[[package]]
name = "markupsafe"
version = "2.1.1"
description = "Safely add untrusted strings to HTML/XML markup."
category = "main"
optional = false
python-versions = ">=3.7"
[[package]]
name = "pelican"
version = "4.8.0"
description = "Static site generator supporting Markdown and reStructuredText"
category = "main"
optional = false
python-versions = ">=3.6,<4.0"
[package.dependencies]
blinker = ">=1.4"
docutils = ">=0.16"
feedgenerator = ">=1.9"
jinja2 = ">=2.7"
pygments = ">=2.6"
python-dateutil = ">=2.8"
pytz = ">=2020.1"
rich = ">=10.1"
unidecode = ">=1.1"
[package.extras]
markdown = ["markdown (>=3.1)"]
[[package]]
name = "pelican-drafts"
version = "0.1.1"
description = "Add a browsable drafts listing to your Pelican website"
category = "main"
optional = false
python-versions = ">=3.7"
[package.dependencies]
pelican = ">=4.2.0"
[package.extras]
test = ["pytest (<5.4)"]
qa = ["flake8", "pytest-cov"]
[[package]]
name = "pelican-sitemap"
version = "1.0.2"
description = "Pelican plugin to generate sitemap in plain-text or XML format"
category = "main"
optional = false
python-versions = ">=3.6,<4.0"
[package.dependencies]
pelican = ">=4.5,<5.0"
[package.extras]
markdown = ["markdown (>=3.2.2,<4.0.0)"]
[[package]]
name = "pelican-yaml-metadata"
version = "2.0.0"
description = ""
category = "main"
optional = false
python-versions = "*"
develop = false
[package.dependencies]
markdown = ">=3.3.4,<4.0.0"
pelican = ">=4.5,<5.0.0"
pyYAML = ">=5.4.1,<6.0.0"
[package.source]
type = "git"
url = "https://github.com/pR0Ps/pelican-yaml-metadata.git"
reference = "cdc1b9708916410e455e8e258e3d39a9d575c7b5"
resolved_reference = "cdc1b9708916410e455e8e258e3d39a9d575c7b5"
[[package]]
name = "pygments"
version = "2.12.0"
description = "Pygments is a syntax highlighting package written in Python."
category = "main"
optional = false
python-versions = ">=3.6"
[[package]]
name = "python-dateutil"
version = "2.8.2"
description = "Extensions to the standard Python datetime module"
category = "main"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7"
[package.dependencies]
six = ">=1.5"
[[package]]
name = "pytz"
version = "2022.1"
description = "World timezone definitions, modern and historical"
category = "main"
optional = false
python-versions = "*"
[[package]]
name = "pyyaml"
version = "5.4.1"
description = "YAML parser and emitter for Python"
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*"
[[package]]
name = "rich"
version = "12.5.1"
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
category = "main"
optional = false
python-versions = ">=3.6.3,<4.0.0"
[package.dependencies]
commonmark = ">=0.9.0,<0.10.0"
pygments = ">=2.6.0,<3.0.0"
typing-extensions = {version = ">=4.0.0,<5.0", markers = "python_version < \"3.9\""}
[package.extras]
jupyter = ["ipywidgets (>=7.5.1,<8.0.0)"]
[[package]]
name = "six"
version = "1.16.0"
description = "Python 2 and 3 compatibility utilities"
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
[[package]]
name = "typer"
version = "0.6.1"
description = "Typer, build great CLIs. Easy to code. Based on Python type hints."
category = "main"
optional = false
python-versions = ">=3.6"
[package.dependencies]
click = ">=7.1.1,<9.0.0"
[package.extras]
test = ["rich (>=10.11.0,<13.0.0)", "isort (>=5.0.6,<6.0.0)", "black (>=22.3.0,<23.0.0)", "mypy (==0.910)", "pytest-sugar (>=0.9.4,<0.10.0)", "pytest-xdist (>=1.32.0,<2.0.0)", "coverage (>=5.2,<6.0)", "pytest-cov (>=2.10.0,<3.0.0)", "pytest (>=4.4.0,<5.4.0)", "shellingham (>=1.3.0,<2.0.0)"]
doc = ["mdx-include (>=1.4.1,<2.0.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "mkdocs (>=1.1.2,<2.0.0)"]
dev = ["pre-commit (>=2.17.0,<3.0.0)", "flake8 (>=3.8.3,<4.0.0)", "autoflake (>=1.3.1,<2.0.0)"]
all = ["rich (>=10.11.0,<13.0.0)", "shellingham (>=1.3.0,<2.0.0)", "colorama (>=0.4.3,<0.5.0)"]
[[package]]
name = "typing-extensions"
version = "4.3.0"
description = "Backported and Experimental Type Hints for Python 3.7+"
category = "main"
optional = false
python-versions = ">=3.7"
[[package]]
name = "unidecode"
version = "1.3.4"
description = "ASCII transliterations of Unicode text"
category = "main"
optional = false
python-versions = ">=3.5"
[[package]]
name = "zipp"
version = "3.8.1"
description = "Backport of pathlib-compatible object wrapper for zip files"
category = "main"
optional = false
python-versions = ">=3.7"
[package.extras]
docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)", "jaraco.tidelift (>=1.4)"]
testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.3)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)"]
[metadata]
lock-version = "1.1"
python-versions = "^3.7"
content-hash = "3ca0141fb5fadc6455945b7155c807b726d6dc0e6f0b87f4f4e60fa6190f5835"
[metadata.files]
blinker = []
click = []
colorama = []
commonmark = []
dnd-rolltable = []
docutils = []
feedgenerator = []
importlib-metadata = []
invoke = []
jinja2 = []
markdown = []
markupsafe = []
pelican = []
pelican-drafts = []
pelican-sitemap = []
pelican-yaml-metadata = []
pygments = []
python-dateutil = []
pytz = []
pyyaml = []
rich = []
six = []
typer = []
typing-extensions = []
unidecode = []
zipp = []

View File

@ -9,7 +9,7 @@ packages = [
]
[tool.poetry.dependencies]
python = "^3.7"
python = "^3.10"
# cli business
typer = "latest"
@ -27,6 +27,7 @@ pelican-yaml-metadata = { git = "https://github.com/pR0Ps/pelican-yaml-metadata.
dnd-rolltable = { git = "https://github.com/evilchili/dnd-rolltable", branch = 'main' }
[tool.poetry.scripts]
site = "site_tools.cli:app"
roll-table = "rolltable.cli:app"
pelican = "site_tools.tasks:pelican_main"

View File

@ -0,0 +1,63 @@
import click
import sys
import typer
from enum import Enum
from site_tools.tasks import CONFIG
from site_tools.content_manager import create
CONFIG.update(
templates_path='markdown-templates',
)
app = typer.Typer()
class ContentType(str, Enum):
post = 'post'
lore = 'lore'
monster = 'monster'
region = 'region'
page = 'page'
@app.command()
def new(
content_type: ContentType = typer.Argument(
...,
help="The type of content to create.",
),
title: str = typer.Argument(
...,
help="The title of the content.",
),
category: str = typer.Argument(
None,
help='Override the default category; required for "post" content.',
),
template: str = typer.Argument(
None,
help="Override the default template for the content_type.",
),
template_dir: str = typer.Argument(
CONFIG['templates_path'],
help="Override the default location for markdown templates.",
)
) -> None:
if not category:
match content_type:
case 'post':
print("You must specify a category for 'post' content.")
sys.exit()
case 'monster':
category = 'beastiary'
case 'region':
category = 'regions'
case _:
category = content_type
click.edit(filename=create(content_type, title, template_dir, category,
template or content_type))
if __name__ == '__main__':
app()

View File

@ -0,0 +1,9 @@
---
# dm/some-post.md
title: some post
author: evilchili
tags: ContentType.post
date: 2022-08-02 17:59:59.899095
status: draft
---

View File

@ -0,0 +1,50 @@
---
# regions/region-name.md
title: region name
author: evilchili
tags: ContentType.region
date: 2022-08-02 17:57:41.572598
category: regions
template: region
region:
name: region name
size: 10
terrain: difficult
shelter: none
water_source: none
travel:
dc: 10
critical_success:
critical_fail:
forage:
dc: 10
critical_success:
critical_fail:
track:
dc: 10
critical_success:
critical_fail:
evade:
dc: 10
critical_success:
critical_fail:
survey:
dc: 10
critical_success:
critical_fail:
encounter_chance: 5
special:
weather:
d1:
d2:
d3:
d4:
d5:
d6:
d7:
d8:
status: draft
---
Region description goes here.

View File

@ -0,0 +1,44 @@
import datetime
from jinja2 import Environment, FileSystemLoader
from pathlib import Path
from pelican.writers import Writer
from pelican.utils import slugify, sanitised_join
from site_tools.tasks import SETTINGS
def create(content_type: str, title: str, template_dir: str,
category: str = None, template: str = None) -> str:
"""
Return the path to a new source file.
"""
base_path = Path(__file__).parent.absolute()
def _slugify(s):
return slugify(s, regex_subs=SETTINGS['SLUG_REGEX_SUBSTITUTIONS'])
template_path = Path(template_dir)
template_name = template + ".md"
if not (template_path / template_name).exists():
template_name = 'default.md'
print("Not found. Using default markdown template.")
template_source = Environment(
loader=FileSystemLoader(template_path),
trim_blocks=True,
).get_template(template_name)
target_filename = _slugify(title) + '.md'
relpath = Path(slugify(category)) if category else ''
target_path = base_path / SETTINGS['PATH'] / relpath
dest = sanitised_join(str(target_path / target_filename))
SETTINGS['WRITE_SELECTED'].append(dest)
writer = Writer(target_path, settings=SETTINGS)
writer.write_file(name=target_filename, template=template_source, context={
'title': title,
'tags': content_type,
'date': datetime.datetime.now(),
'filename': str(relpath / target_filename)
})
return dest

View File

@ -1,19 +1,12 @@
# -*- coding: utf-8 -*-
import os
import inspect
import shlex
import shutil
import datetime
from pathlib import Path
from jinja2 import Environment, FileSystemLoader
from invoke import task
from invoke.main import program
from pelican import main as pelican_main
from pelican.writers import Writer
from pelican.utils import slugify, sanitised_join
from pelican.settings import DEFAULT_CONFIG, get_settings_from_file
OPEN_BROWSER_ON_SERVE = True
@ -135,71 +128,6 @@ def publish(c):
**CONFIG))
@task
def monster(c, name, t='default'):
"""Create a new monster"""
return create_new_content(c, name, template=t, category='beastiary')
@task
def lore(c, title, t='default'):
"""Create a new lore post"""
return create_new_content(c, title, template=t, category='lore')
@task
def post(c, category, title, t=None, template_dir='markdown-templates'):
"""Create a new post in the specified category"""
return create_new_content(c, title, template=t or category, template_dir=template_dir, category=category)
@task
def page(c, title, t='default', template_dir='markdown-templates'):
"""Create a new page"""
return create_new_content(c, title, template=t, template_dir=template_dir, output_path='pages')
def create_new_content(c, title, template_dir='markdown-templates', category="", template=None, output_path=''):
"""Create new content of a given type and invoke the editor."""
content_type = template or inspect.stack()[1].function
print(f"Creating new '{content_type}' content: \"{category}/{title}\"")
base_path = Path(__file__).parent.absolute()
def _slugify(s):
return slugify(s, regex_subs=DEFAULT_CONFIG['SLUG_REGEX_SUBSTITUTIONS'])
template_path = Path(template_dir)
template_name = _slugify(content_type) + ".md"
if not (template_path / template_name).exists():
template_name = 'default.md'
print("Using default markdown template.")
target_filename = _slugify(title) + '.md'
target_path = base_path / SETTINGS['PATH']
if output_path:
target_path = target_path / output_path
if category:
target_path = target_path / slugify(category)
template = Environment(
loader=FileSystemLoader(template_path),
trim_blocks=True,
).get_template(template_name)
dest = sanitised_join(str(target_path / target_filename))
SETTINGS['WRITE_SELECTED'].append(dest)
writer = Writer(target_path, settings=SETTINGS)
writer.write_file(name=target_filename, template=template, context={
'title': title,
'tags': content_type,
'date': datetime.datetime.now(),
'filename': dest
})
c.run(f"$EDITOR {dest}", pty=True)
def pelican_run(cmd):
cmd += ' ' + program.core.remainder # allows to pass-through args to pelican
pelican_main(shlex.split(cmd))

View File

@ -1,10 +1,8 @@
metadata:
headers:
- Roll
- Frequency
- Rarity
- Description
- Effect
die: 20
frequencies:
default:
Common: 0.5
@ -36,6 +34,7 @@ Uncommon:
- Insect Swarms: 1d6 Piercing damage per half-day
- Air of Dread: Succeed on DC 15 WIS save or be frightened for half-day
Rare:
- Magnetic Turmoil: North moves randomly
- Spontaneous Hail: No effect; counts as magical water if consumed
- Glowing Auras: Faerie Fire spell effect
- Heavy Gravity: Disadvantge on STR, DEX checks and saves
@ -47,7 +46,9 @@ Rare:
occupying the same space as a whirlwind at the start of their
turn takes 1d8 bludgeoning damage.
- Tentacles:
At the start of each round, Black Tentacles is cast on a random area. Creatures starting their turn there must succeed on a DC 15 DEX saving throw or take 1d6 bludgeoning damage and be restrained. A creature who starts their turn already restrained takes 1d6 bludgeoning damage.
At the start of each round, Black Tentacles is cast on a random area. Creatures starting their turn there must
succeed on a DC 15 DEX saving throw or take 1d6 bludgeoning damage and be restrained. A creature who starts their
turn already restrained takes 1d6 bludgeoning damage.
- Broken Time:
At the start of each round, the DM rolls a d20. Until the start
of the next round, anyone with initiative score greater than or