Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
berumuron
Boop
Commits
954e4051
Commit
954e4051
authored
Jan 29, 2019
by
berumuron
Browse files
add: Allow overriding articles and pages templates
parent
0b0f035d
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
954e4051
...
...
@@ -334,6 +334,9 @@ This will generate the `site/my_page.html` file:
</html>
```
You can override the default template by setting a `template` variable in the
Yaml header of pages and articles.
## Template syntax
As explained above, you can create templates under the `./templates` folder.
...
...
boop.py
View file @
954e4051
...
...
@@ -52,6 +52,7 @@ class Article:
self
.
meta
=
{}
self
.
meta
.
update
(
configuration
)
self
.
meta
[
"ARTICLE_SLUG"
]
=
slug
self
.
meta
[
"ARTICLE_TEMPLATE"
]
=
"article"
for
key
,
values
in
md
.
Meta
.
items
():
article_key
=
f
"ARTICLE_
{
key
.
upper
()
}
"
# The Markdown's meta extension extract all the values in arrays, even
...
...
@@ -63,7 +64,9 @@ class Article:
self
.
meta
[
"ARTICLE_CONTENT"
]
=
content
# And we initialize a template for the article
article_template_filepath
=
os
.
path
.
join
(
"templates"
,
"article.html"
)
article_template_filepath
=
os
.
path
.
join
(
"templates"
,
f
"
{
self
.
meta
[
'ARTICLE_TEMPLATE'
]
}
.html"
)
self
.
template
=
boopsy
.
Template
(
article_template_filepath
)
def
render
(
self
):
...
...
@@ -123,6 +126,7 @@ class Page:
self
.
meta
=
{}
self
.
meta
.
update
(
configuration
)
self
.
meta
[
"PAGE_SLUG"
]
=
slug
self
.
meta
[
"PAGE_TEMPLATE"
]
=
"page"
yaml_conf
,
page_content
=
extract_yaml_configuration
(
page_content
)
for
key
,
value
in
yaml_conf
.
items
():
article_key
=
f
"PAGE_
{
key
.
upper
()
}
"
...
...
@@ -130,7 +134,9 @@ class Page:
self
.
meta
[
"PAGE_CONTENT"
]
=
page_content
# And we initialize a template for the page
page_template_filepath
=
os
.
path
.
join
(
"templates"
,
"page.html"
)
page_template_filepath
=
os
.
path
.
join
(
"templates"
,
f
"
{
self
.
meta
[
'PAGE_TEMPLATE'
]
}
.html"
)
self
.
template
=
None
if
os
.
path
.
exists
(
page_template_filepath
):
self
.
template
=
boopsy
.
Template
(
page_template_filepath
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment