Skip to content

Commit

Permalink
multi template
Browse files Browse the repository at this point in the history
  • Loading branch information
WaylonWalker committed Jan 3, 2024
1 parent c1832b6 commit d8956ca
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 85 deletions.
165 changes: 93 additions & 72 deletions markata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# markata.dev

[markata.nav]
'markata'='/'
'GitHub'='https://github.com/WaylonWalker/markata'
'markata' = '/'
'GitHub' = 'https://github.com/WaylonWalker/markata'

[markata]
# bump site version to bust GitHub actions cache
Expand All @@ -18,7 +18,7 @@ site_version = 13
## choose your markdown backend
# markdown_backend='markdown'
# markdown_backend='markdown2'
markdown_backend='markdown-it-py'
markdown_backend = 'markdown-it-py'

# 2 weeks in seconds
default_cache_expire = 1209600
Expand All @@ -29,20 +29,20 @@ glob_patterns = "docs/**/*.md,CHANGELOG.md"
output_dir = "markout"
assets_dir = "static"
hooks = [
"markata.plugins.publish_source",
# "markata.plugins.subroute",
"markata.plugins.docs",
# "markata.plugins.prevnext",
# "markata.plugins.service_worker",
"default",
]
"markata.plugins.publish_source",
# "markata.plugins.subroute",
"markata.plugins.docs",
# "markata.plugins.prevnext",
# "markata.plugins.service_worker",
"default",
]
disabled_hooks = [
# "markata.plugins.covers",
# 'markata.plugins.flat_slug',
# 'markata.plugins.seo',
'markata.plugins.heading_link',
'markata.plugins.manifest',
# 'markata.plugins.rss'
# "markata.plugins.covers",
# 'markata.plugins.flat_slug',
# 'markata.plugins.seo',
'markata.plugins.heading_link',
'markata.plugins.manifest',
# 'markata.plugins.rss'
]

## Site Config
Expand All @@ -54,7 +54,6 @@ author_name = "Waylon Walker"
author_email = "[email protected]"
icon = "favicon.ico"
lang = "en"
# post_template = "pages/templates/post_template.html"
repo_url = "https://github.com/waylonwalker/markata"
repo_branch = "main"
theme_color = "#322D39"
Expand All @@ -67,12 +66,19 @@ twitter_card = "summary_large_image"
twitter_creator = "@_waylonwalker"
twitter_site = "@_waylonwalker"

[markata.post_template]
index = 'post.html'
partial = 'post_partial.html'
og = 'og.html'
'raw.md' = 'raw'


# markdown_it flavor
[markata.markdown_it_py]
config='gfm-like'
config = 'gfm-like'
# markdown_it built-in plugins
enable = [ "table" ]
disable = [ "image" ]
enable = ["table"]
disable = ["image"]

# markdown_it built-in plugin options
[markata.markdown_it_py.options_update]
Expand All @@ -90,7 +96,7 @@ plugin = "mdit_py_plugins.admon:admon_plugin"

[[markata.markdown_it_py.plugins]]
plugin = "mdit_py_plugins.attrs:attrs_plugin"
config = {spans = true}
config = { spans = true }

[[markata.markdown_it_py.plugins]]
plugin = "mdit_py_plugins.attrs:attrs_block_plugin"
Expand All @@ -107,7 +113,7 @@ permalinkSymbol = '<svg class="heading-permalink" aria-hidden="true" fill="curre

[[markata.markdown_it_py.plugins]]
plugin = "markata.plugins.md_it_wikilinks:wikilinks_plugin"
config = {markata = "markata"}
config = { markata = "markata" }

# markata feeds
# creating pages of posts
Expand All @@ -125,11 +131,11 @@ config = {markata = "markata"}
# """

[[markata.feeds]]
slug='project-gallery'
title="Project Gallery"
filter="'project-gallery' in str(path)"
sort='title'
card_template="""
slug = 'project-gallery'
title = "Project Gallery"
filter = "'project-gallery' in str(path)"
sort = 'title'
card_template = """
<li class='post' style='background:rgba(255, 255, 255, .05); border:1px solid rgba(255, 255, 255, .2); padding:1rem; margin: 2rem auto;' >
<a href='{{ href }}'><h2>{{ title }}</h2></a>
<ul style='display: flex; list-style-type: None;'>
Expand All @@ -142,17 +148,17 @@ card_template="""
"""

[[markata.feeds]]
slug='docs'
title="Documentation"
filter='"markata" not in slug and "tests" not in slug and "404" not in slug'
sort='slug'
card_template="<li class='post'><a href='{{ href }}'>{{ title }}<p style='color: white; text-decoration: none;'>{{ description }}</p></a> </li>"
slug = 'docs'
title = "Documentation"
filter = '"markata" not in slug and "tests" not in slug and "404" not in slug'
sort = 'slug'
card_template = "<li class='post'><a href='{{ href }}'>{{ title }}<p style='color: white; text-decoration: none;'>{{ description }}</p></a> </li>"

[[markata.feeds]]
slug='all'
title="All Markata Modules"
filter="True"
card_template="""
slug = 'all'
title = "All Markata Modules"
filter = "True"
card_template = """
<li class='post' style='background:rgba(255, 255, 255, .05); border:1px solid rgba(255, 255, 255, .2); padding:1rem; margin: 2rem auto;' >
<a href='{{ href }}'>
<a href='{{ href }}'>{{ title }}</a>
Expand All @@ -164,10 +170,10 @@ card_template="""
"""

[[markata.feeds]]
slug='core-modules'
title="Markata Core Modules"
filter="'plugin' not in slug and 'test' not in slug and title.endswith('.py')"
card_template="""
slug = 'core-modules'
title = "Markata Core Modules"
filter = "'plugin' not in slug and 'test' not in slug and title.endswith('.py')"
card_template = """
<li class='post' style='background:rgba(255, 255, 255, .05); border:1px solid rgba(255, 255, 255, .2); padding:1rem; margin: 2rem auto;' >
<a href='{{ href }}'>
<a href='{{ href }}'>{{ title }}</a>
Expand All @@ -179,10 +185,10 @@ card_template="""
"""

[[markata.feeds]]
slug='plugins'
title="Markata Plugins"
filter="'plugin' in slug and 'test' not in slug"
card_template="""
slug = 'plugins'
title = "Markata Plugins"
filter = "'plugin' in slug and 'test' not in slug"
card_template = """
<li class='post' style='background:rgba(255, 255, 255, .05); border:1px solid rgba(255, 255, 255, .2); padding:1rem; margin: 2rem auto;' >
<a href='{{ href }}'>
<a href='/{{ href }}/'>{{ title }}</a>
Expand All @@ -194,60 +200,75 @@ card_template="""
"""

[markata.jinja_md]
ignore=[
'jinja_md.md',
'post_template.md',
'publish_html.md',
'CHANGELOG.md',
'feeds.md',
ignore = [
'jinja_md.md',
'post_template.md',
'publish_html.md',
'CHANGELOG.md',
'feeds.md',
]

[[markata.head.meta]]
name = "og:author_email"
content = "[email protected]"

[markata.tui]
new_cmd=['tmux', 'popup', 'markata', 'new', 'post']
new_cmd = ['tmux', 'popup', 'markata', 'new', 'post']

[[markata.tui.keymap]]
name='new'
key='n'
name = 'new'
key = 'n'

[markata.summary]
grid_attr = ['tags', 'series']

[[markata.summary.filter_count]]
name='drafts'
filter="published == 'False'"
color='red'
name = 'drafts'
filter = "published == 'False'"
color = 'red'

[[markata.summary.filter_count]]
name='articles'
color='dark_orange'
name = 'articles'
color = 'dark_orange'

[[markata.summary.filter_count]]
name='py_modules'
filter='"plugin" not in slug and "docs" not in str(path)'
color="yellow1"
name = 'py_modules'
filter = '"plugin" not in slug and "docs" not in str(path)'
color = "yellow1"

[markata.summary.filter_count.published]
filter="published == 'True'"
color='green1'
filter = "published == 'True'"
color = 'green1'

[markata.summary.filter_count.plugins]
filter='"plugin" in slug and "docs" not in str(path)'
color="blue"
filter = '"plugin" in slug and "docs" not in str(path)'
color = "blue"

[markata.summary.filter_count.docs]
filter="'docs' in str(path)"
color='purple'
filter = "'docs' in str(path)"
color = 'purple'

[markata.post_model]
include = ['date', 'description', 'published', 'slug', 'title', 'content', 'html']
repr_include = ['date', 'description', 'published', 'slug', 'title', 'output_html']
include = [
'date',
'description',
'published',
'slug',
'title',
'content',
'html',
]
repr_include = [
'date',
'description',
'published',
'slug',
'title',
'output_html',
]

[markata.render_markdown]
backend='markdown-it-py'
backend = 'markdown-it-py'

# [markata.markdown_it_py]
# config='gfm-like'
Expand All @@ -271,7 +292,7 @@ plugin = "mdit_py_plugins.admon:admon_plugin"

[[markata.render_markdown.extensions]]
plugin = "mdit_py_plugins.attrs:attrs_plugin"
config = {spans = true}
config = { spans = true }

[[markata.render_markdown.extensions]]
plugin = "mdit_py_plugins.attrs:attrs_block_plugin"
Expand All @@ -288,7 +309,7 @@ plugin = "mdit_py_plugins.anchors:anchors_plugin"

[[markata.render_markdown.extensions]]
plugin = "markata.plugins.md_it_wikilinks:wikilinks_plugin"
config = {markata = "markata"}
config = { markata = "markata" }

[markata.glob]
glob_patterns = "docs/**/*.md,CHANGELOG.md"
Expand Down
6 changes: 3 additions & 3 deletions markata/plugins/md_it_wikilinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def wikilinks_plugin(
def _wikilinks_inline(state: StateInline, silent: bool):
try:
if (
state.srcCharCode[state.pos] != start_char
or state.srcCharCode[state.pos + 1] != start_char
state.srcCharCode[state.pos] != start_char or
state.srcCharCode[state.pos + 1] != start_char
):
return False
except IndexError:
Expand All @@ -100,7 +100,7 @@ def _wikilinks_inline(state: StateInline, silent: bool):
if not found_closing:
return False

text = state.src[state.pos + 2 : end].strip()
text = state.src[state.pos + 2: end].strip()
state.pos = end + 2

if silent:
Expand Down
4 changes: 3 additions & 1 deletion markata/plugins/post_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import dateparser
import pydantic
from pydantic import Field
import yaml
from polyfactory.factories.pydantic_factory import ModelFactory
from pydantic import ConfigDict
Expand All @@ -21,7 +22,7 @@


class Post(pydantic.BaseModel):
markata: Any = None
markata: Any = Field(None, exclude=True)
path: Path
slug: Optional[str] = None
href: Optional[str] = None
Expand Down Expand Up @@ -189,6 +190,7 @@ def parse_markdown(cls, markata, path: Union[Path, str], **kwargs) -> "Post":
"markata": markata,
"path": path,
"content": content,
"raw": text,
**fm,
}

Expand Down
10 changes: 9 additions & 1 deletion markata/plugins/post_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,15 @@ class Post(pydantic.BaseModel):
def default_template(cls, v, *, values):
if v is None:
return values["markata"].config.post_template
return v
if isinstance(v, str):
v = {"index": v}
if isinstance(values["markata"].config.post_template, str):
config_template = {
"index": values["markata"].config.post_template,
}
else:
config_template = values["markata"].config.post_template
return {**config_template, **v}


@hook_impl(tryfirst=True)
Expand Down
2 changes: 2 additions & 0 deletions markata/plugins/publish_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def save(markata: "Markata") -> None:
if slug == "index":
slug = ""
output_html = article.output_html
elif "." in slug:
output_html = article.output_html.parent / slug
else:
slug = slugify(slug)
output_html = article.output_html.parent / slug / "index.html"
Expand Down
2 changes: 1 addition & 1 deletion markata/templates/content_base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "content_base.html" %}
{% extends "base.html" %}
{% block body %}
{% include "nav.html" %}
{% block content %} {% endblock %}
Expand Down
9 changes: 2 additions & 7 deletions markata/templates/post.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{% extends "base.html" %}
{% extends "content_base.html" %}
{% block content %}
<article>
{% include "title.html" %}
<section class="body">
{{ body }}
</section>
</article>
{% include "post_partial.html" %}
{% endblock %}
6 changes: 6 additions & 0 deletions markata/templates/post_partial.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<article>
{% include "title.html" %}
<section class="body">
{{ body }}
</section>
</article>
1 change: 1 addition & 0 deletions markata/templates/raw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ post.raw }}

0 comments on commit d8956ca

Please sign in to comment.