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
9a2c6459
Commit
9a2c6459
authored
Feb 24, 2019
by
berumuron
Browse files
Extract function to build an article from filepath
parent
e3c382ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
boop.py
View file @
9a2c6459
...
...
@@ -180,6 +180,17 @@ def extract_yaml_configuration(content):
return
{},
content
def
build_article_from_filepath
(
filepath
,
configuration
,
serie
=
None
):
"""Read a file and initialize an Article from it.
"""
filepath_no_ext
,
_
=
os
.
path
.
splitext
(
filepath
)
slug
=
os
.
path
.
basename
(
filepath_no_ext
)
with
open
(
filepath
,
"r"
)
as
article_file
:
return
Article
(
slug
,
article_file
.
read
(),
configuration
=
configuration
,
serie
=
serie
)
def
list_dirs
(
path
):
"""List all the directories within a path.
"""
...
...
@@ -335,32 +346,18 @@ def main(environment):
articles_by_series
[
serie
]
=
[]
for
filename
in
list_files
(
dirpath
,
only
=
[
"md"
]):
# We read the article file and initialize an Article from it
filename_no_ext
,
_
=
os
.
path
.
splitext
(
filename
)
slug
=
os
.
path
.
basename
(
filename_no_ext
)
article_filepath
=
os
.
path
.
join
(
dirpath
,
filename
)
with
open
(
article_filepath
,
"r"
)
as
article_file
:
article
=
Article
(
slug
,
article_file
.
read
(),
configuration
=
configuration
,
serie
=
serie
,
)
articles
.
append
(
article
)
if
serie
:
articles_by_series
[
serie
].
append
(
article
)
article
=
build_article_from_filepath
(
article_filepath
,
configuration
,
serie
)
articles
.
append
(
article
)
if
serie
:
articles_by_series
[
serie
].
append
(
article
)
for
filename
in
list_files
(
articles_path
,
only
=
[
"md"
]):
# We read the article file and initialize an Article from it
filename_no_ext
,
_
=
os
.
path
.
splitext
(
filename
)
slug
=
os
.
path
.
basename
(
filename_no_ext
)
article_filepath
=
os
.
path
.
join
(
articles_path
,
filename
)
with
open
(
article_filepath
,
"r"
)
as
article_file
:
article
=
Article
(
slug
,
article_file
.
read
(),
configuration
=
configuration
)
articles
.
append
(
article
)
article
=
build_article_from_filepath
(
article_filepath
,
configuration
)
articles
.
append
(
article
)
# STEP 2: we write all the pages and articles
for
page
in
pages
:
...
...
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