pysocha 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. pysocha-0.1.0/.gitignore +16 -0
  2. pysocha-0.1.0/.python-version +1 -0
  3. pysocha-0.1.0/PKG-INFO +21 -0
  4. pysocha-0.1.0/README.md +3 -0
  5. pysocha-0.1.0/example/content/blog_posts/filenames_are_ignored.md +10 -0
  6. pysocha-0.1.0/example/content/blog_posts/first_post.md +10 -0
  7. pysocha-0.1.0/example/content/blog_posts/second_post.md +8 -0
  8. pysocha-0.1.0/example/content/blog_posts/some_random_name.md +7 -0
  9. pysocha-0.1.0/example/content/blog_posts/unlisted_post.md +12 -0
  10. pysocha-0.1.0/example/content/extra_files/download_me.txt +1 -0
  11. pysocha-0.1.0/example/content/extra_files/extra.css +3 -0
  12. pysocha-0.1.0/example/content/extra_files/extra.js +3 -0
  13. pysocha-0.1.0/example/content/extra_files/logo.png +0 -0
  14. pysocha-0.1.0/example/content/extra_files/main.css +9 -0
  15. pysocha-0.1.0/example/content/extra_files/main.js +2 -0
  16. pysocha-0.1.0/example/content/extra_files/readme.md +5 -0
  17. pysocha-0.1.0/example/content/extra_files/sub_dirs/download_me2.txt +1 -0
  18. pysocha-0.1.0/example/content/extra_files/zips.gif +0 -0
  19. pysocha-0.1.0/example/content/pages/index.md +6 -0
  20. pysocha-0.1.0/example/content/pages/test.md +7 -0
  21. pysocha-0.1.0/example/example-config.yaml +31 -0
  22. pysocha-0.1.0/example/templates/author.jinja2 +19 -0
  23. pysocha-0.1.0/example/templates/authors.jinja2 +8 -0
  24. pysocha-0.1.0/example/templates/base.jinja2 +20 -0
  25. pysocha-0.1.0/example/templates/blog.jinja2 +8 -0
  26. pysocha-0.1.0/example/templates/listing.jinja2 +18 -0
  27. pysocha-0.1.0/example/templates/page.jinja2 +4 -0
  28. pysocha-0.1.0/example/templates/tag.jinja2 +19 -0
  29. pysocha-0.1.0/example/templates/tags.jinja2 +8 -0
  30. pysocha-0.1.0/pyproject.toml +38 -0
  31. pysocha-0.1.0/requirements-dev.lock +63 -0
  32. pysocha-0.1.0/requirements.lock +63 -0
  33. pysocha-0.1.0/src/pysocha/__init__.py +52 -0
  34. pysocha-0.1.0/src/pysocha/__main__.py +7 -0
  35. pysocha-0.1.0/src/pysocha/build.py +252 -0
  36. pysocha-0.1.0/src/pysocha/config.py +35 -0
  37. pysocha-0.1.0/src/pysocha/markdown.py +27 -0
  38. pysocha-0.1.0/src/pysocha/preview.py +36 -0
  39. pysocha-0.1.0/tools.sh +31 -0
@@ -0,0 +1,16 @@
1
+ # python generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # venv
10
+ .venv
11
+ venv/
12
+ env/
13
+
14
+ # Specific to this project
15
+ generated/
16
+ scratch.py
@@ -0,0 +1 @@
1
+ 3.12.3
pysocha-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.3
2
+ Name: pysocha
3
+ Version: 0.1.0
4
+ Summary: Extremely simple static site generator
5
+ Author-email: Tod Hansmann <githubpub@todandlorna.com>
6
+ Requires-Python: >=3.8
7
+ Requires-Dist: flask>=3.0.3
8
+ Requires-Dist: jinja2>=3.1.4
9
+ Requires-Dist: linkify-it-py>=2.0.3
10
+ Requires-Dist: markdown-it-py>=3.0.0
11
+ Requires-Dist: mdit-py-plugins>=0.4.1
12
+ Requires-Dist: python-dateutil>=2.9.0.post0
13
+ Requires-Dist: python-frontmatter>=1.1.0
14
+ Requires-Dist: python-slugify>=8.0.4
15
+ Requires-Dist: pyyaml>=6.0.1
16
+ Requires-Dist: typer>=0.12.3
17
+ Description-Content-Type: text/markdown
18
+
19
+ # pysocha
20
+
21
+ pysocha is a static site generator of as simple a variety as we can make for our needs.
@@ -0,0 +1,3 @@
1
+ # pysocha
2
+
3
+ pysocha is a static site generator of as simple a variety as we can make for our needs.
@@ -0,0 +1,10 @@
1
+ ---
2
+ # These are all optional
3
+ Author: 'Not Tod'
4
+ Tags: ['testing', 'generated', 'fourth']
5
+ # These are not optional at all
6
+ PostedDate: 'Sun Sep 28 10:36:28 MST 2003'
7
+ Title: 'This is the fourth post'
8
+ ---
9
+
10
+ The filename doesn't matter, only the title
@@ -0,0 +1,10 @@
1
+ ---
2
+ Author: 'Tod Hansmann'
3
+ Tags: ['first', 'testing', 'generated']
4
+ NeverUsed: 'This is never actually used, but I can throw it in for later use if I want'
5
+ PostedDate: 'Thu Sep 25 10:36:28 MST 2003'
6
+ Title: 'Test Blog Up and Running'
7
+ ---
8
+ This should be our first post. I could technically generate this or manipulate it after the fact, or use part of it, or mix it up <b>with HTML</b> if I want.
9
+
10
+ Really anything I want, as complex as I want that fits into markdown. Who knows, maybe I'll add some scripting component or something if I need something fancier later, but today is not that day.
@@ -0,0 +1,8 @@
1
+ ---
2
+ Author: 'Also Not Tod'
3
+ Tags: ['third', 'testing', 'generated'] # Yes, I tagged it third.
4
+ NeverUsed: 'This is never actually used, but I can throw it in for later use if I want'
5
+ PostedDate: 'Fri Sep 26 20:36:28 MST 2003'
6
+ Title: 'Oh hello, oh hello, second post to you'
7
+ ---
8
+ This should be our second post. This is how I'm linking to the [first post](first_post.md).
@@ -0,0 +1,7 @@
1
+ ---
2
+ Author: 'Tod Hansmann'
3
+ Tags: ['generated', 'third']
4
+ PostedDate: 'Sun Sep 28 9:36:28 MST 2003'
5
+ Title: 'This is the third post'
6
+ ---
7
+ Third post, hopefully an hour ahead of the fourth.
@@ -0,0 +1,12 @@
1
+ ---
2
+ # These are all optional
3
+ Author: 'Not Tod'
4
+ Tags: ['testing', 'generated', 'fourth']
5
+ # These are not optional at all
6
+ PostedDate: 'Sun Sep 29 10:36:28 MST 2003'
7
+ Title: 'This is the unlisted post'
8
+ Unlisted: true
9
+ ---
10
+
11
+ This post isn't listed. Maybe it's something I prefer to link directly do, maybe it's something I want to password protect, maybe it's a preview. It won't appear in listings or atom feeds until it's listed.
12
+
@@ -0,0 +1 @@
1
+ This is just filler, to demonstrate a file you want downloadable but aren't going to put in any templates or anything.
@@ -0,0 +1,3 @@
1
+ p {
2
+ color: cornflowerblue;
3
+ }
@@ -0,0 +1,3 @@
1
+ var extra = 5;
2
+ main = main + main;
3
+ console.print("from extra: " + main)
@@ -0,0 +1,9 @@
1
+ .tag_list_item, .author_list_item, .author_post {
2
+ border: solid black 2px;
3
+ margin: 4px;
4
+ }
5
+
6
+ .tag, .tags, .author {
7
+ padding: 4px;
8
+ margin: 4px;
9
+ }
@@ -0,0 +1,2 @@
1
+ var main = 4;
2
+ console.print("from main: " + main)
@@ -0,0 +1,5 @@
1
+ This comes from the extra_files directory in the example site setup.
2
+
3
+ All extra_files get placed in the root of the generated target.
4
+
5
+ If you're reading this in the generated folder, that's because we put it there, but git is set to ignore everything except it.
@@ -0,0 +1 @@
1
+ This is just another filler, to demonstrate a file you want downloadable in a sub directory but aren't going to put in any templates or anything.
@@ -0,0 +1,6 @@
1
+ ---
2
+ Title: "Welcome to This Land"
3
+ ---
4
+ This should be the main page. Check it out!
5
+
6
+ Linking to [Test](index.md) and [the blog listing](/theblog/listing1.html)
@@ -0,0 +1,7 @@
1
+ ---
2
+ Title: "Test Page"
3
+ ExtraHeaders:
4
+ - '<link rel="stylesheet" href="extra.css" type="text/css" />'
5
+ - '<script type="text/javascript" src="extra.js"></script>'
6
+ ---
7
+ This should be the second test page. Check it out! <img src="/zips.gif" />
@@ -0,0 +1,31 @@
1
+ # All of these have defaults, too, these are the bare minimum
2
+ contentDir: "content" # Where content should be found
3
+ outputDir: "generated" # Where the output should be put, wiping it every time we start
4
+ templatesDir: "templates" # Where the templates are
5
+ siteTitle: "Example dot Com!" # The title of the site
6
+ descending: True # Whether to sort post times in descending order, default true with newest content first
7
+ defaultExtension: ".html" # If you prefer to use .foo or something for your server, here you go
8
+ startPage: "index.html" # make sure the extension matches the defaultExtension
9
+
10
+ # These keys are used for general files, like the index page, but you can add more
11
+ # and they will be passed to templates as named variables
12
+ pageConfig: # Where things start for pages, but note you could override these in the frontmatter of a page
13
+ pageTitle: "Example dot Com!" # The title of the page
14
+ pageDefaultTemplate: "page.jinja2"
15
+
16
+ # These keys are used for blog posts and listings, but you can add more
17
+ # and they will be passed to templates as named variables
18
+ blogConfig: # The Blog requires more config, but again you can override many of these in the frontmatter of a post
19
+ title: "Example blog"
20
+ blogBaseDir: "theblog" # The url path to the blog
21
+ blogTemplate: "blog.jinja2"
22
+ listingTemplate: "listing.jinja2"
23
+ listingPaginationNum: 5 # How many posts per listing page
24
+ listingKeysNeeded: ['hook'] # If you have extra logic in your listing template, you can require extra in your posts
25
+ atomFeeds: True # Generate atom feeds for the blog and each tag
26
+ tagsTemplate: "tags.jinja2" # List all tags
27
+ tagTemplate: "tag.jinja2" # Each tag also gets a listing of its own
28
+ tagPaginationNum: 5 # How many posts per tag page
29
+ authorsTemplate: "authors.jinja2" # All authors
30
+ authorTemplate: "author.jinja2" # Each author gets a listing of their own
31
+ authorPaginationNum: 10 # How many posts per author page
@@ -0,0 +1,19 @@
1
+ {% extends "base.jinja2" %}
2
+ {% block title %}Posts authored by {{ Author }}{% endblock %}
3
+ {% block content %}
4
+ {% for post in posts %}
5
+ <div class="author_post">
6
+ <h3><a href="{{ post.slugify }}">{{ post.Title }}</a></h3>
7
+ <div>posted: {{ post.PostedDate }}</div>
8
+ </div>
9
+ {% endfor %}
10
+ <div id = 'page_numbers'>Pages
11
+ {% if page_num > 1 %}
12
+ <span class="pages"><a href="{{ author_file }}{{ page_num - 1 }}.html">&lt;</a></span>
13
+ {% endif %}
14
+ <span class="pages current_page">{{ page_num }}</span>
15
+ {% if page_num < total_pages %}
16
+ <span class="pages"><a href="{{ author_file }}{{ page_num + 1 }}.html">&gt;</a></span>
17
+ {% endif %}
18
+ </div>
19
+ {% endblock %}
@@ -0,0 +1,8 @@
1
+ {% extends "base.jinja2" %}
2
+ {% block content %}
3
+ {% for author, posts in authors.items() %}
4
+ <div class="author_list_item">
5
+ <h3><a href="{{ author.replace(' ', '_') }}1.html">{{ author }}: {{ posts|length }} posts</a></h3>
6
+ </div>
7
+ {% endfor %}
8
+ {% endblock %}
@@ -0,0 +1,20 @@
1
+ <html>
2
+ <head>
3
+ <title>{{ title }}</title>
4
+ <meta name="author" content="Tod Hansmann">
5
+ <link href="/main.css" rel="stylesheet" type="text/css" />
6
+ <script src="/main.js" type="javascript"></script>
7
+ {{ extraHeaders }}
8
+ </head>
9
+ <body>
10
+ <div id="header">
11
+ <img src="/logo.png" />{{ title }}
12
+ </div>
13
+ <div id="content">
14
+ {% block content %}
15
+ {% endblock %}
16
+ </div>
17
+ {% block extra_footer %}
18
+ {% endblock %}
19
+ </body>
20
+ </html>
@@ -0,0 +1,8 @@
1
+ {% extends "base.jinja2" %}
2
+ {% block content %}
3
+ <h1>{{ title }}</h1>
4
+ <div class="post_author">Written by <a href="author_{{ Author.replace(' ', '_') }}1.html">{{ Author }}</a></div>
5
+ <div class="posted_date">On: {{ PostedDate }}</div>
6
+ <div class="tags">{% for tag in Tags %}<span class="tag"><a href="tag_{{ tag }}1.html">{{ tag }}</a></span>{% endfor %}</div>
7
+ {{ content }}
8
+ {% endblock %}
@@ -0,0 +1,18 @@
1
+ {% extends "base.jinja2" %}
2
+ {% block content %}
3
+ {% for post in posts %}
4
+ <div class="author_post">
5
+ <h3><a href="{{ post.slugify }}">{{ post.Title }}</a></h3>
6
+ <div>posted: {{ post.PostedDate }}</div>
7
+ </div>
8
+ {% endfor %}
9
+ <div id = 'page_numbers'>Pages
10
+ {% if page_num > 1 %}
11
+ <span class="pages"><a href="listing{{ page_num - 1 }}.html">&lt;</a></span>
12
+ {% endif %}
13
+ <span class="pages current_page">{{ page_num }}</span>
14
+ {% if page_num < total_pages %}
15
+ <span class="pages"><a href="listing{{ page_num + 1 }}.html">&gt;</a></span>
16
+ {% endif %}
17
+ </div>
18
+ {% endblock %}
@@ -0,0 +1,4 @@
1
+ {% extends "base.jinja2" %}
2
+ {% block content %}
3
+ {{ content }}
4
+ {% endblock %}
@@ -0,0 +1,19 @@
1
+ {% extends "base.jinja2" %}
2
+ {% block title %}Posts for tag {{ tag }}{% endblock %}
3
+ {% block content %}
4
+ {% for post in posts %}
5
+ <div class="tag_post">
6
+ <h3><a href="{{ post.slugify }}">{{ post.Title }}</a></h3>
7
+ <div>posted: {{ post.PostedDate }}</div>
8
+ </div>
9
+ {% endfor %}
10
+ <div id = 'page_numbers'>Pages
11
+ {% if page_num > 1 %}
12
+ <span class="pages"><a href="{{ tag_file }}{{ page_num - 1 }}.html">&lt;</a></span>
13
+ {% endif %}
14
+ <span class="pages current_page">{{ page_num }}</span>
15
+ {% if page_num < total_pages %}
16
+ <span class="pages"><a href="{{ tag_file }}{{ page_num + 1 }}.html">&gt;</a></span>
17
+ {% endif %}
18
+ </div>
19
+ {% endblock %}
@@ -0,0 +1,8 @@
1
+ {% extends "base.jinja2" %}
2
+ {% block content %}
3
+ {% for tag, posts in tags.items() %}
4
+ <div class="tag_list_item">
5
+ <h3><a href="tag_{{ tag.replace(' ', '_') }}1.html">{{ tag }}: {{ posts|length }} posts</a></h3>
6
+ </div>
7
+ {% endfor %}
8
+ {% endblock %}
@@ -0,0 +1,38 @@
1
+ [project]
2
+ name = "pysocha"
3
+ version = "0.1.0"
4
+ description = "Extremely simple static site generator"
5
+ authors = [
6
+ { name = "Tod Hansmann", email = "githubpub@todandlorna.com" }
7
+ ]
8
+ dependencies = [
9
+ "markdown-it-py>=3.0.0",
10
+ "jinja2>=3.1.4",
11
+ "typer>=0.12.3",
12
+ "pyyaml>=6.0.1",
13
+ "linkify-it-py>=2.0.3",
14
+ "mdit-py-plugins>=0.4.1",
15
+ "python-frontmatter>=1.1.0",
16
+ "flask>=3.0.3",
17
+ "python-slugify>=8.0.4",
18
+ "python-dateutil>=2.9.0.post0",
19
+ ]
20
+ readme = "README.md"
21
+ requires-python = ">= 3.8"
22
+
23
+ [project.scripts]
24
+ pysocha = 'pysocha:main'
25
+
26
+ [build-system]
27
+ requires = ["hatchling"]
28
+ build-backend = "hatchling.build"
29
+
30
+ [tool.rye]
31
+ managed = true
32
+ dev-dependencies = []
33
+
34
+ [tool.hatch.metadata]
35
+ allow-direct-references = true
36
+
37
+ [tool.hatch.build.targets.wheel]
38
+ packages = ["src/pysocha"]
@@ -0,0 +1,63 @@
1
+ # generated by rye
2
+ # use `rye lock` or `rye sync` to update this lockfile
3
+ #
4
+ # last locked with the following flags:
5
+ # pre: false
6
+ # features: []
7
+ # all-features: false
8
+ # with-sources: false
9
+ # generate-hashes: false
10
+
11
+ -e file:.
12
+ blinker==1.8.2
13
+ # via flask
14
+ click==8.1.7
15
+ # via flask
16
+ # via typer
17
+ flask==3.0.3
18
+ # via pysocha
19
+ itsdangerous==2.2.0
20
+ # via flask
21
+ jinja2==3.1.4
22
+ # via flask
23
+ # via pysocha
24
+ linkify-it-py==2.0.3
25
+ # via pysocha
26
+ markdown-it-py==3.0.0
27
+ # via mdit-py-plugins
28
+ # via pysocha
29
+ # via rich
30
+ markupsafe==2.1.5
31
+ # via jinja2
32
+ # via werkzeug
33
+ mdit-py-plugins==0.4.1
34
+ # via pysocha
35
+ mdurl==0.1.2
36
+ # via markdown-it-py
37
+ pygments==2.18.0
38
+ # via rich
39
+ python-dateutil==2.9.0.post0
40
+ # via pysocha
41
+ python-frontmatter==1.1.0
42
+ # via pysocha
43
+ python-slugify==8.0.4
44
+ # via pysocha
45
+ pyyaml==6.0.1
46
+ # via pysocha
47
+ # via python-frontmatter
48
+ rich==13.7.1
49
+ # via typer
50
+ shellingham==1.5.4
51
+ # via typer
52
+ six==1.16.0
53
+ # via python-dateutil
54
+ text-unidecode==1.3
55
+ # via python-slugify
56
+ typer==0.12.3
57
+ # via pysocha
58
+ typing-extensions==4.12.1
59
+ # via typer
60
+ uc-micro-py==1.0.3
61
+ # via linkify-it-py
62
+ werkzeug==3.0.3
63
+ # via flask
@@ -0,0 +1,63 @@
1
+ # generated by rye
2
+ # use `rye lock` or `rye sync` to update this lockfile
3
+ #
4
+ # last locked with the following flags:
5
+ # pre: false
6
+ # features: []
7
+ # all-features: false
8
+ # with-sources: false
9
+ # generate-hashes: false
10
+
11
+ -e file:.
12
+ blinker==1.8.2
13
+ # via flask
14
+ click==8.1.7
15
+ # via flask
16
+ # via typer
17
+ flask==3.0.3
18
+ # via pysocha
19
+ itsdangerous==2.2.0
20
+ # via flask
21
+ jinja2==3.1.4
22
+ # via flask
23
+ # via pysocha
24
+ linkify-it-py==2.0.3
25
+ # via pysocha
26
+ markdown-it-py==3.0.0
27
+ # via mdit-py-plugins
28
+ # via pysocha
29
+ # via rich
30
+ markupsafe==2.1.5
31
+ # via jinja2
32
+ # via werkzeug
33
+ mdit-py-plugins==0.4.1
34
+ # via pysocha
35
+ mdurl==0.1.2
36
+ # via markdown-it-py
37
+ pygments==2.18.0
38
+ # via rich
39
+ python-dateutil==2.9.0.post0
40
+ # via pysocha
41
+ python-frontmatter==1.1.0
42
+ # via pysocha
43
+ python-slugify==8.0.4
44
+ # via pysocha
45
+ pyyaml==6.0.1
46
+ # via pysocha
47
+ # via python-frontmatter
48
+ rich==13.7.1
49
+ # via typer
50
+ shellingham==1.5.4
51
+ # via typer
52
+ six==1.16.0
53
+ # via python-dateutil
54
+ text-unidecode==1.3
55
+ # via python-slugify
56
+ typer==0.12.3
57
+ # via pysocha
58
+ typing-extensions==4.12.1
59
+ # via typer
60
+ uc-micro-py==1.0.3
61
+ # via linkify-it-py
62
+ werkzeug==3.0.3
63
+ # via flask
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+ import os
3
+ import typer
4
+ import yaml
5
+ from yaml import Loader
6
+ from pprint import pprint
7
+ from typing_extensions import Annotated
8
+ from .config import override_config
9
+ from .markdown import parseCommonMark
10
+ from .preview import makePreviewServer
11
+ from .build import buildSite
12
+
13
+ mark = """---
14
+ Title: Foo and Bar
15
+ Author: Me and myself
16
+ Date: 2004-09-25:12:28:00
17
+ ---
18
+ ### This is a header
19
+
20
+ * List 1
21
+ * List 2
22
+ * List 3
23
+
24
+ This is some stuff *bold* or not.
25
+ """
26
+
27
+ app = typer.Typer()
28
+
29
+ def initialize(config_file: str):
30
+ return override_config(yaml.load(config_file, Loader=Loader))
31
+
32
+ @app.command()
33
+ def hello(name: Annotated[str, typer.Argument()] = 'World') -> str:
34
+ print(f"Hello {name}!")
35
+
36
+ @app.command()
37
+ def preview(config_file: Annotated[typer.FileText, typer.Option('--config-file', '-c')] = './config.yaml'):
38
+ config = initialize(config_file)
39
+ output_dir = os.path.join(os.getcwd(), config['outputDir'])
40
+ server = makePreviewServer(output_dir, config['startPage'], config['defaultExtension'])
41
+ server.config['SEND_FILE_MAX_AGE_DEFAULT'] = 5
42
+ buildSite(config)
43
+ server.run(host='0.0.0.0')
44
+
45
+
46
+ @app.command()
47
+ def build(config_file: Annotated[typer.FileText, typer.Option('--config-file', '-c')] = './config.yaml'):
48
+ config = initialize(config_file)
49
+ pprint(config)
50
+ pprint(parseCommonMark(mark)['markdown'])
51
+ buildSite(config)
52
+
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+ from . import app
3
+
4
+
5
+ if __name__ == '__main__':
6
+ app()
7
+
@@ -0,0 +1,252 @@
1
+ import dateutil.parser
2
+ import jinja2
3
+ import math
4
+ import os
5
+ import re
6
+ import shutil
7
+
8
+ from slugify import slugify
9
+
10
+ from .markdown import parseCommonMark
11
+
12
+
13
+ def get_markdown_files(directory):
14
+ """
15
+ This function is used to get all the markdown files in a directory
16
+ """
17
+ files = []
18
+ for file in os.listdir(directory):
19
+ if file.endswith('.md'):
20
+ files.append(file)
21
+ return files
22
+
23
+ def generate_blog_posts(config: dict):
24
+ """
25
+ We go through all blog posts and their related optional outputs like tags or authors, depending on config
26
+ """
27
+
28
+ templateDir = config['templatesDir']
29
+ templateLoader = jinja2.FileSystemLoader(searchpath=templateDir)
30
+ templateEnv = jinja2.Environment( loader=templateLoader )
31
+ template = templateEnv.get_template(config['blogConfig']['blogTemplate'])
32
+ outputDir = os.path.join(os.getcwd(), config['outputDir'])
33
+
34
+ posts = {}
35
+ sorted_posts = []
36
+ posts_dir = os.path.join(config['contentDir'], 'blog_posts')
37
+
38
+ # First we need to get all the content and frontmatter into posts for later
39
+ for post in get_markdown_files(posts_dir):
40
+ with open(os.path.join(posts_dir, post), 'r') as f:
41
+ file = f.read()
42
+ mark = parseCommonMark(file)
43
+ post_data = mark['frontmatter']
44
+ post_data['PostedDate'] = dateutil.parser.parse(post_data['PostedDate'])
45
+ post_template = template
46
+ # If we override the template for that page, here it gets invoked
47
+ if 'Template' in mark['frontmatter']:
48
+ post_template = templateEnv.get_template(mark['frontmatter']['Template'])
49
+ # Same with file extension, which opens some nice scripting possibilities
50
+ file_ext = mark['frontmatter'].get('Extension', config['defaultExtension'])
51
+ post_data['slugify'] = slugify(mark['frontmatter']['Title']) + file_ext
52
+ output_filename = os.path.join(outputDir + '/' + config['blogConfig']['blogBaseDir'] + '/' + post_data['slugify'])
53
+ # This will give all frontmatter and the content to the jinja template
54
+ post_data['content'] = mark['markdown']
55
+ post_data['rendered'] = post_template.render(post_data)
56
+ post_data['rendered'] = config['_pattern'].sub(lambda m: config['_replacements'][m.group(0)], post_data['rendered'])
57
+ posts[post] = post_data
58
+ if post_data.get('Unlisted') is None:
59
+ sorted_posts.append(post_data)
60
+
61
+ sorted_posts.sort(key=lambda post: post['PostedDate'], reverse=config['descending'])
62
+ blog_config = config['blogConfig']
63
+ listing_template = blog_config['listingTemplate']
64
+ listings = []
65
+ tags_template = blog_config['tagsTemplate']
66
+ tag_template = blog_config['tagTemplate']
67
+ tags = {}
68
+ authors_template = blog_config['authorsTemplate']
69
+ author_template = blog_config['authorTemplate']
70
+ authors = {}
71
+ output_dir = os.path.join(config['outputDir'], blog_config['blogBaseDir'])
72
+ file_ext = config['defaultExtension']
73
+ os.makedirs(output_dir, exist_ok=True)
74
+
75
+ # We'll need to make all the blog posts
76
+ for blog_post in sorted_posts:
77
+ output_filename = os.path.join(output_dir, blog_post['slugify'])
78
+ with open(output_filename, 'w+') as f:
79
+ f.write(blog_post['rendered'])
80
+
81
+ # Now populate lists, first one only if the post has all the keys needed for a listing
82
+ listings.append(blog_post)
83
+ # Make a list of posts for each tag out there
84
+ if tags_template and tag_template and blog_post.get('Tags'):
85
+ for tag in blog_post['Tags']:
86
+ if tag not in tags:
87
+ tags[tag] = []
88
+ tags[tag].append(blog_post)
89
+ # Make a list of posts for each author out there
90
+ if authors_template and author_template and blog_post.get('Author'):
91
+ if blog_post['Author'] not in authors:
92
+ authors[blog_post['Author']] = []
93
+ authors[blog_post['Author']].append(blog_post)
94
+
95
+ # Make them templates objects
96
+ listing_template = templateEnv.get_template(listing_template)
97
+ tags_template = templateEnv.get_template(tags_template)
98
+ tag_template = templateEnv.get_template(tag_template)
99
+ authors_template = templateEnv.get_template(authors_template)
100
+ author_template = templateEnv.get_template(author_template)
101
+
102
+ # Listings, and they need pages
103
+ page_limit = blog_config['listingPaginationNum']
104
+ total_pages = int(math.floor(len(listings) / page_limit) + 1)
105
+ ranges = range(1, total_pages + (total_pages > 1)) or [1]
106
+ for page_num in ranges:
107
+ file_num = str(page_num) + file_ext
108
+ offset = (page_num - 1) * page_limit
109
+ output_filename = os.path.join(output_dir, 'listing' + file_num)
110
+ with open(output_filename, 'w+') as f:
111
+ f.write(listing_template.render({'posts': listings[offset:offset+page_limit],
112
+ 'all_posts': sorted_posts,
113
+ 'title': blog_config['title'],
114
+ 'page_num': page_num,
115
+ 'total_pages': total_pages}))
116
+
117
+ output_filename = os.path.join(output_dir, 'tags' + file_ext)
118
+ with open(output_filename, 'w+') as f:
119
+ f.write(tags_template.render({'tags': tags, 'title': 'Tags', 'all_posts': sorted_posts}))
120
+ for tag, posts in tags.items():
121
+ page_limit = blog_config['tagPaginationNum']
122
+ total_pages = int(math.floor(len(posts) / page_limit)) + 1
123
+ ranges = range(1, total_pages + (total_pages > 1)) or [1]
124
+ for page_num in ranges:
125
+ file_num = str(page_num) + file_ext
126
+ offset = (page_num - 1) * page_limit
127
+ tag_file = 'tag_' + tag.replace(' ', '_')
128
+ output_filename = os.path.join(output_dir, tag_file + file_num)
129
+ with open(output_filename, 'w+') as f:
130
+ f.write(tag_template.render({'posts': posts[offset:offset+page_limit],
131
+ 'all_posts': sorted_posts,
132
+ 'tag': tag,
133
+ 'tag_file': tag_file,
134
+ 'title': 'Posts for tag: ' + tag,
135
+ 'page_num': page_num,
136
+ 'total_pages': total_pages}))
137
+
138
+ output_filename = os.path.join(output_dir, 'authors' + file_ext)
139
+ with open(output_filename, 'w+') as f:
140
+ f.write(authors_template.render({'authors': authors, 'title': 'Authors', 'all_posts': sorted_posts}))
141
+ for author, posts in authors.items():
142
+ if 'authorPaginationNum' in blog_config:
143
+ page_limit = blog_config['authorPaginationNum']
144
+ total_pages = int(math.floor(len(posts) / page_limit) + 1)
145
+ ranges = range(1, total_pages + (total_pages > 1)) or [1]
146
+ for page_num in ranges:
147
+ file_num = str(page_num) + file_ext
148
+ offset = (page_num - 1) * page_limit
149
+ author_file = 'author_' + author.replace(' ', '_')
150
+ output_filename = os.path.join(output_dir, author_file + file_num)
151
+ with open(output_filename, 'w+') as f:
152
+ f.write(author_template.render({'author': author,
153
+ 'author_file': author_file,
154
+ 'title': 'Posts for author: ' + author,
155
+ 'posts': posts[offset:offset+page_limit],
156
+ 'all_posts': sorted_posts,
157
+ 'page_num': page_num,
158
+ 'total_pages': total_pages}))
159
+ else:
160
+ output_filename = os.path.join(output_dir, 'author_' + author.replace(' ', '_') + file_ext)
161
+ with open(output_filename, 'w+') as f:
162
+ f.write(author_template.render({'author': author,
163
+ 'all_posts': sorted_posts,
164
+ 'title': 'Posts for author: ' + author,
165
+ 'posts': posts}))
166
+
167
+ def generate_pages(config: dict):
168
+ """
169
+ We go through all the possibilities for generating any page related details
170
+ """
171
+ templateDir = config['templatesDir']
172
+ templateLoader = jinja2.FileSystemLoader(searchpath=templateDir)
173
+ templateEnv = jinja2.Environment( loader=templateLoader )
174
+ template = templateEnv.get_template(config['pageConfig']['pageDefaultTemplate'])
175
+ outputDir = os.path.join(os.getcwd(), config['outputDir'])
176
+
177
+ pages = {}
178
+ pages_dir = os.path.join(config['contentDir'], 'pages')
179
+ for page in get_markdown_files(pages_dir):
180
+ pages[page] = {}
181
+ with open(os.path.join(pages_dir, page), 'r') as f:
182
+ file = f.read()
183
+ mark = parseCommonMark(file)
184
+ page_template = template
185
+ # If we override the template for that page, here it gets invoked
186
+ if 'Template' in mark['frontmatter']:
187
+ page_template = templateEnv.get_template(mark['frontmatter']['Template'])
188
+ # Same with file extension, which opens some nice scripting possibilities
189
+ file_ext = mark['frontmatter'].get('Extension', config['defaultExtension'])
190
+ pages[page]['slugify'] = page.rstrip('.md')
191
+ output_filename = os.path.join(outputDir + '/' + pages[page]['slugify'] + file_ext)
192
+ print(output_filename)
193
+ # This will give all frontmatter and the content to the jinja template
194
+ context = mark['frontmatter']
195
+ context['content'] = mark['markdown']
196
+ with open(output_filename, 'w+') as f:
197
+ foo = page_template.render(context)
198
+ foo = config['_pattern'].sub(lambda m: config['_replacements'][m.group(0)], foo)
199
+ f.write(foo)
200
+
201
+ def generate_extras(config: dict):
202
+ """
203
+ EVERY site should have extra files, even if it's just CSS or JS files, so process them here very simply
204
+ """
205
+ extra_files_dir = os.path.join(config['contentDir'], 'extra_files')
206
+ output_dir = os.path.join(config['outputDir'])
207
+ shutil.copytree(extra_files_dir, output_dir, dirs_exist_ok=True)
208
+
209
+ def build_pages_replacement_map(config: dict) -> dict:
210
+ """
211
+ We need to replace instances of things like "index.md" with "index.html" anywhere it's reference in markdown, so
212
+ just build a map for pages here ahead of the markdown conversion
213
+ """
214
+ pages_dir = os.path.join(config['contentDir'], 'pages')
215
+ replacements = {}
216
+ for page in get_markdown_files(pages_dir):
217
+ replacements[page] = page.replace('.md', config['defaultExtension'])
218
+ return replacements
219
+
220
+ def build_posts_replacement_map(config: dict) -> dict:
221
+ """
222
+ We also need a replacement map for posts, which means we need to replace them with their slugs
223
+ """
224
+ pages_dir = os.path.join(config['contentDir'], 'blog_posts')
225
+ # At some point, if we link to the listings or just the blog base as me, we'll need that in this patterns too,
226
+ # but that's a mistake anyway, as we should be using the default extension and know what we're linking to
227
+ replacements = {}
228
+ for page in get_markdown_files(pages_dir):
229
+ with open(os.path.join(pages_dir, page), 'r') as f:
230
+ file = f.read()
231
+ mark = parseCommonMark(file)
232
+ replacements[page] = config['blogConfig']['blogBaseDir'] + '/' + slugify(mark['frontmatter']['Title']) + config['defaultExtension']
233
+ return replacements
234
+
235
+ def buildSite(config: dict):
236
+ if os.path.exists(config['outputDir']):
237
+ shutil.rmtree(config['outputDir'])
238
+ os.makedirs(config['outputDir'])
239
+ pages_map = build_pages_replacement_map(config)
240
+ posts_map = build_posts_replacement_map(config)
241
+ # Now that we have the maps, we can build the replacements and the pattern for regex on all files
242
+ config['_replacements'] = {**pages_map, **posts_map}
243
+ rep = dict((re.escape(k), v) for k, v in config['_replacements'].items())
244
+ config['_pattern'] = re.compile("|".join(rep.keys()))
245
+ if len(config['_replacements'].keys()) > len(pages_map.keys()) + len(posts_map.keys()):
246
+ print('Pages and Posts have overlapping names. Please fix this.')
247
+ print('Overlappng names: ', pages_map.keys() & posts_map.keys())
248
+ exit(1)
249
+ generate_extras(config)
250
+ generate_pages(config)
251
+ generate_blog_posts(config)
252
+ return
@@ -0,0 +1,35 @@
1
+ import yaml
2
+
3
+ default_yaml = """
4
+ contentDir: "content"
5
+ outputDir: "generated"
6
+ templatesDir: "templates"
7
+ siteTitle: "Example dot Com!"
8
+ descending: True
9
+ defaultExtension: ".html"
10
+ startPage: "index.html"
11
+ pageConfig:
12
+ pageTitle: "Example dot Com!"
13
+ pageDefaultTemplate: "page.jinja2"
14
+ blogConfig:
15
+ title: "Example blog"
16
+ blogBaseDir: "blog"
17
+ blogTemplate: "blog.jinja2"
18
+ listingTemplate: "listing.jinja2"
19
+ listingPagination_num: 5
20
+ listingKeysNeeded: ['hook']
21
+ atomFeed: True
22
+ tagsTemplate: "tags.jinja2"
23
+ tagTemplate: "tag.jinja2"
24
+ tagPaginationNum: 5
25
+ authorsTemplate: "authors.jinja2"
26
+ authorTemplate: "author.jinja2"
27
+ authorPaginationNum: 10
28
+ """
29
+
30
+ CONFIG = yaml.load(default_yaml, Loader=yaml.Loader)
31
+
32
+ def override_config(overrides: dict) -> dict:
33
+ CONFIG.update(overrides)
34
+ return CONFIG
35
+
@@ -0,0 +1,27 @@
1
+ import frontmatter
2
+ from markdown_it import MarkdownIt
3
+ from mdit_py_plugins.front_matter import front_matter_plugin
4
+
5
+ MD = None
6
+
7
+ def _initialize(options: dict = None):
8
+ global MD
9
+ if options is None:
10
+ options = {}
11
+ MD = (
12
+ MarkdownIt("commonmark", options)
13
+ .use(front_matter_plugin)
14
+ .enable(['table', 'linkify', 'replacements'])
15
+ )
16
+
17
+ def parseCommonMark(markdown: str, options: dict = None):
18
+ global MD
19
+ if options is None:
20
+ options = {}
21
+ if MD is None:
22
+ _initialize(options)
23
+ retVal = {
24
+ 'frontmatter': frontmatter.loads(markdown).metadata,
25
+ 'markdown': MD.render(markdown)
26
+ }
27
+ return retVal
@@ -0,0 +1,36 @@
1
+ import mimetypes
2
+ from flask import Flask, make_response
3
+ from functools import update_wrapper
4
+
5
+ # Yes, I know, globals bad, it's a preview dev tool
6
+ previewServer = Flask(__name__, static_url_path='')
7
+ _startPage = 'index.html'
8
+
9
+ def nocache(f):
10
+ def new_func(*args, **kwargs):
11
+ resp = make_response(f(*args, **kwargs))
12
+ resp.cache_control.no_cache = True
13
+ return resp
14
+ return update_wrapper(new_func, f)
15
+
16
+ @previewServer.after_request
17
+ def nocache_response(response):
18
+ response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
19
+ response.headers['Expires'] = '-1'
20
+ return response
21
+
22
+ @previewServer.route('/hello')
23
+ def hello_world():
24
+ return 'Hello World!'
25
+
26
+ @previewServer.route('/')
27
+ @nocache
28
+ def root():
29
+ return previewServer.send_static_file(_startPage)
30
+
31
+ def makePreviewServer(static_folder: str = 'generated', start_page: str = 'index.html', extension: str = 'html'):
32
+ global previewServer, _startPage
33
+ mimetypes.add_type('text/html', extension)
34
+ previewServer.static_folder=static_folder
35
+ _startPage = start_page
36
+ return previewServer
pysocha-0.1.0/tools.sh ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ THISSCRIPT=$(basename $0)
6
+
7
+ GITHUB_OUTPUT=${GITHUB_OUTPUT:-$(mktemp)}
8
+
9
+ # Modify for the help message
10
+ usage() {
11
+ echo "${THISSCRIPT} command"
12
+ echo "Executes the step command in the script."
13
+ exit 0
14
+ }
15
+
16
+ setup() {
17
+ echo "Not really a thing yet."
18
+ }
19
+
20
+ # This should be last in the script, all other functions are named beforehand.
21
+ case "$1" in
22
+ "setup")
23
+ shift
24
+ setup "$@"
25
+ ;;
26
+ *)
27
+ usage
28
+ ;;
29
+ esac
30
+
31
+ exit 0