Skip to content
GitLab
Menu
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
96cd2873
Commit
96cd2873
authored
Dec 12, 2018
by
berumuron
Browse files
Change how article attributes are accessed
parent
9be19d59
Changes
1
Show whitespace changes
Inline
Side-by-side
boop.py
View file @
96cd2873
...
...
@@ -30,16 +30,16 @@ class ProgramError(Exception):
class
Article
:
def
__init__
(
self
,
slug
,
article_content
):
self
.
slug
=
slug
def
__init__
(
self
,
slug
,
article_content
,
configuration
=
{}):
# We convert the file's content into HTML
md
=
markdown
.
Markdown
(
extensions
=
[
"meta"
,
"fenced_code"
,
"attr_list"
])
self
.
content
=
md
.
convert
(
article_content
)
content
=
md
.
convert
(
article_content
)
# We get the local variables from the Markdown file (metadata)
# which will be accessible in the article template
self
.
meta
=
{}
self
.
meta
.
update
(
configuration
)
self
.
meta
[
"ARTICLE_SLUG"
]
=
slug
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
...
...
@@ -47,15 +47,23 @@ class Article:
# the template system, for the moment we just get the first value of
# the array.
self
.
meta
[
article_key
]
=
values
[
0
]
self
.
meta
[
"ARTICLE_CONTENT"
]
=
content
# And we initialize a template for the article
article_template_filepath
=
os
.
path
.
join
(
"theme"
,
"article.html"
)
self
.
template
=
boopsy
.
Template
(
article_template_filepath
)
def
render
(
self
):
variables
=
self
.
meta
.
copy
()
variables
[
"ARTICLE_CONTENT"
]
=
self
.
content
return
self
.
template
.
render
(
variables
)
return
self
.
template
.
render
(
self
.
meta
)
def
slug
(
self
):
return
self
.
meta
[
"ARTICLE_SLUG"
]
def
title
(
self
):
return
self
.
meta
.
get
(
"ARTICLE_TITLE"
,
"An article"
)
def
content
(
self
):
return
self
.
meta
[
"ARTICLE_CONTENT"
]
def
dir_tree
(
path
):
...
...
@@ -116,7 +124,7 @@ def main():
# And write them in the ./site folder
for
article
in
articles
:
output_filepath
=
os
.
path
.
join
(
output_path
,
f
"
{
article
.
slug
}
.html"
)
output_filepath
=
os
.
path
.
join
(
output_path
,
f
"
{
article
.
slug
()
}
.html"
)
with
open
(
output_filepath
,
"w"
)
as
output_file
:
output_file
.
write
(
article
.
render
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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