diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..10a8a80 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include pixywerk2/defaults/*.yaml \ No newline at end of file diff --git a/READMES/project-layout.md b/READMES/project-layout.md new file mode 100644 index 0000000..c51aa86 --- /dev/null +++ b/READMES/project-layout.md @@ -0,0 +1,69 @@ +# Project Layout # + +It is recommended that in general your project for PixyWerk2 site be layed out like: +``` +project_top/ + Makefile - Convenient for building your site + src/ - All "source" pages are contained in here. + .meta - Top-level default metadata is set here + templates/ - Templates go in here + default.jinja2 - Default template that will be used if none are specified + publish/ - The path the build process will create, where the post-processed files go. +``` + + +## Makefile ## + +Makefile is suggested, but not essential, for encapsulating your build commands to produce your +site. Something as simple as: + +``` +build: src/templates/* src/* + python -mpixywerk2 src publish +``` + +## src/ ## + +This is the top level path that all of your templates, page fragments, images, etc. will be stored. This is basically the "source code" for your site. + +## src/.meta ## + +This is the top level metadata that is used as the default for all subsidiary metadata. It is in JSON format (with JS style comments). See for more information. + +Example .meta file: + +``` +{ + "title": "My Website", // this is the default title applied if none are specified + "author": "Super Web Dude", + "site_root": "http://example.com", + "uuid-oid-root": "example.com-", // this is used to generate UUIDs +} +``` + +## src/templates/ ## + +Templates are all stored here, as this is the search path for Jinja. + +## templates/default.jinja2 ## + +If a page specifies a `template` metadata key, the named template is used, however, if not this template is used. Generally speaking this is a complete HTML file, with the `{{ content }}` template string placed where the content of subsidiary pages will be embedded. + +A simple default.jinja2 example: + +``` + + + +{{ title }} + + +{{content}} + + +``` + + +## publish/ ## + +This is arbitrary, and will be created by pixywerk at build time, but it will be the root path that should be published to your web server. diff --git a/TODO.md b/TODO.md index efe697a..bd5221a 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ # TODO # -* Pygments pretty printing of source code et al. including exposing that to the template API. +* Pygments pretty printing of source code et al. including exposing that to the template API (`pygment_format(get_file_content('whatever.py'))`). * Smart CSS things (fill in the processors) # Maybe # diff --git a/examples/pixywerk.com/Makefile b/examples/pixywerk.com/Makefile new file mode 100644 index 0000000..1816135 --- /dev/null +++ b/examples/pixywerk.com/Makefile @@ -0,0 +1,2 @@ +build: src/templates/* src/* src/images/* src/posts/* + python -mpixywerk2 src publish diff --git a/examples/pixywerk.com/README.md b/examples/pixywerk.com/README.md new file mode 100644 index 0000000..e45996a --- /dev/null +++ b/examples/pixywerk.com/README.md @@ -0,0 +1,4 @@ +# Pixywerk.com Example # + +This is an example blog system with the features most blogs would have (posts, tag cloud, atom/rss feeds, +index with images). diff --git a/examples/pixywerk.com/foo b/examples/pixywerk.com/foo new file mode 100644 index 0000000..e69de29 diff --git a/examples/pixywerk.com/publish/css/main.css b/examples/pixywerk.com/publish/css/main.css new file mode 100644 index 0000000..cd7f0d6 --- /dev/null +++ b/examples/pixywerk.com/publish/css/main.css @@ -0,0 +1,3 @@ + + +body { margin: 10% 10% 0 10% } \ No newline at end of file diff --git a/examples/pixywerk.com/publish/images/20190415-0.jpg b/examples/pixywerk.com/publish/images/20190415-0.jpg new file mode 100644 index 0000000..a054489 Binary files /dev/null and b/examples/pixywerk.com/publish/images/20190415-0.jpg differ diff --git a/examples/pixywerk.com/publish/images/placeholder b/examples/pixywerk.com/publish/images/placeholder new file mode 100644 index 0000000..e69de29 diff --git a/examples/pixywerk.com/publish/index.html b/examples/pixywerk.com/publish/index.html new file mode 100644 index 0000000..d6f20b2 --- /dev/null +++ b/examples/pixywerk.com/publish/index.html @@ -0,0 +1,13 @@ + + + + + + +

This is my index!!

+ +for i in posts[:5]: + +get metadata, fill in post image/text summary with link + + \ No newline at end of file diff --git a/examples/pixywerk.com/publish/posts/2019-04-15.html b/examples/pixywerk.com/publish/posts/2019-04-15.html new file mode 100644 index 0000000..af953b3 --- /dev/null +++ b/examples/pixywerk.com/publish/posts/2019-04-15.html @@ -0,0 +1,18 @@ + + + My first post + + + + +
+

Author: Cas Rusnov

+

Published: 2019-04-16T01:42:27.156392+00:00 + +

+
+

This is an example post!

+

yo fresh

+

There are many posts like it but this one is mine.

+ + \ No newline at end of file diff --git a/examples/pixywerk.com/publish/templates/default.jinja2 b/examples/pixywerk.com/publish/templates/default.jinja2 new file mode 100644 index 0000000..1d7e899 --- /dev/null +++ b/examples/pixywerk.com/publish/templates/default.jinja2 @@ -0,0 +1,9 @@ + + + {{ metadata.title }} + + + + {{ content }} + + diff --git a/examples/pixywerk.com/src/.meta b/examples/pixywerk.com/src/.meta new file mode 100644 index 0000000..1836c12 --- /dev/null +++ b/examples/pixywerk.com/src/.meta @@ -0,0 +1,6 @@ +{ +"author": "Cas Rusnov", +"author_email": "rusnovn@gmail.com", +"uuid-oid-root": "pixywerk.com/", +"site_root": "https://pixywerk.com/" +} \ No newline at end of file diff --git a/examples/pixywerk.com/src/css/main.css b/examples/pixywerk.com/src/css/main.css new file mode 100644 index 0000000..cd7f0d6 --- /dev/null +++ b/examples/pixywerk.com/src/css/main.css @@ -0,0 +1,3 @@ + + +body { margin: 10% 10% 0 10% } \ No newline at end of file diff --git a/examples/pixywerk.com/src/images/20190415-0.jpg b/examples/pixywerk.com/src/images/20190415-0.jpg new file mode 100644 index 0000000..a054489 Binary files /dev/null and b/examples/pixywerk.com/src/images/20190415-0.jpg differ diff --git a/examples/pixywerk.com/src/images/placeholder b/examples/pixywerk.com/src/images/placeholder new file mode 100644 index 0000000..e69de29 diff --git a/examples/pixywerk.com/src/index.thtml b/examples/pixywerk.com/src/index.thtml new file mode 100644 index 0000000..b65db2c --- /dev/null +++ b/examples/pixywerk.com/src/index.thtml @@ -0,0 +1,5 @@ +

This is my index!!

+ +for i in posts[:5]: + +get metadata, fill in post image/text summary with link diff --git a/examples/pixywerk.com/src/posts/2019-04-15.thtml b/examples/pixywerk.com/src/posts/2019-04-15.thtml new file mode 100644 index 0000000..d959916 --- /dev/null +++ b/examples/pixywerk.com/src/posts/2019-04-15.thtml @@ -0,0 +1,12 @@ + +
+

Author: {{ metadata.author }}

+

Published: {{ get_time_iso8601(metadata.stat.ctime) }} + {% if metadata.stat.mtime-metadata.stat.ctime > 512 %} + Updated: {{ get_time_iso8601(metadata.stat.mtime) }} + {% endif %} +

+
+

This is an example post!

+

yo fresh

+

There are many posts like it but this one is mine.

diff --git a/examples/pixywerk.com/src/posts/2019-04-15.thtml.meta b/examples/pixywerk.com/src/posts/2019-04-15.thtml.meta new file mode 100644 index 0000000..ebe5666 --- /dev/null +++ b/examples/pixywerk.com/src/posts/2019-04-15.thtml.meta @@ -0,0 +1,4 @@ +{ +"title":"My first post", +"featured":"../images/20190415-0.jpg" +} diff --git a/examples/pixywerk.com/src/templates/default.jinja2 b/examples/pixywerk.com/src/templates/default.jinja2 new file mode 100644 index 0000000..1d7e899 --- /dev/null +++ b/examples/pixywerk.com/src/templates/default.jinja2 @@ -0,0 +1,9 @@ + + + {{ metadata.title }} + + + + {{ content }} + + diff --git a/pixywerk2/__main__.py b/pixywerk2/__main__.py index be9065d..062b331 100644 --- a/pixywerk2/__main__.py +++ b/pixywerk2/__main__.py @@ -8,12 +8,14 @@ import argparse import logging import os +import shutil import sys import time from typing import Dict, List, cast from .processchain import ProcessorChains +from .processors.processors import PassthroughException from .metadata import MetaTree from .template_tools import file_list, file_name, file_content, file_metadata, time_iso8601 @@ -73,8 +75,11 @@ def main() -> int: "dir-template": "default-dir.jinja2", "filters": {}, "build-time": time.time(), - "build-datetime": time.ctime(), "uuid-oid-root": "pixywerk", + "summary": "", + "description": "", + "author": "", + "author_email": "" } meta_tree = MetaTree(args.root, default_metadata) file_list_cache = cast(Dict, {}) @@ -109,9 +114,13 @@ def main() -> int: chain = process_chains.get_chain_for_filename(os.path.join(root, f), ctx=metadata) print("process {} -> {}".format(os.path.join(root, f), os.path.join(target_dir, chain.output_filename))) if not args.dry_run: - with open(os.path.join(target_dir, chain.output_filename), "w") as outfile: - for line in chain.output: - outfile.write(line) + try: + with open(os.path.join(target_dir, chain.output_filename), "w") as outfile: + for line in chain.output: + outfile.write(line) + except PassthroughException: + shutil.copyfile(os.path.join(root, f), os.path.join(target_dir, chain.output_filename)) + return 0 diff --git a/pixywerk2/processors/passthrough.py b/pixywerk2/processors/passthrough.py index 9a0601d..cc6511b 100644 --- a/pixywerk2/processors/passthrough.py +++ b/pixywerk2/processors/passthrough.py @@ -2,7 +2,7 @@ import os -from .processors import Processor +from .processors import Processor, PassthroughException from ..utils import guess_mime from typing import Iterable, Optional, Dict, cast @@ -49,7 +49,7 @@ class PassThrough(Processor): Returns: iterable: The post-processed output stream """ - return input_file + raise PassthroughException("passthrough") def extension(self, oldname: str, ctx: Optional[Dict] = None) -> str: """Return the mimetype of the post-processed file. diff --git a/pixywerk2/processors/processors.py b/pixywerk2/processors/processors.py index 3161654..0ff970e 100644 --- a/pixywerk2/processors/processors.py +++ b/pixywerk2/processors/processors.py @@ -3,6 +3,10 @@ import abc from typing import Iterable, Optional, Dict +class PassthroughException(Exception): + """Raised when the processor would like the file to pass through unchanged.""" + + class ProcessorException(Exception): # pragma: no cover """A base exception class to be used by processor objects.""" diff --git a/setup.py b/setup.py index 5635ec0..fa63b07 100644 --- a/setup.py +++ b/setup.py @@ -43,12 +43,13 @@ setup( # 'cookbook = spicerack.cookbook:main', # ], # }, + include_package_data=True, extras_require=EXTRAS_REQUIRE, install_requires=INSTALL_REQUIRES, - keywords=["cms", "website", "compiler"] + keywords=["cms", "website", "compiler"], license="MIT", long_description=LONG_DESCRIPTION, - name="pixywerk2", # Must be the same used for __version__ in __init__.py + name="pixywerk2", packages=find_packages(exclude=["*.tests", "*.tests.*"]), platforms=["GNU/Linux"], setup_requires=SETUP_REQUIRES,