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
3f235329
Commit
3f235329
authored
Jan 11, 2019
by
berumuron
Browse files
Load configuration at the beginning
parent
61b3d16d
Changes
1
Hide whitespace changes
Inline
Side-by-side
boop.py
View file @
3f235329
...
...
@@ -144,6 +144,36 @@ def main(environment):
os
.
remove
(
output_path
)
os
.
mkdir
(
output_path
)
# Load the configuration (it can be overidden by a configuration.yml file)
configuration
=
{
"SITE_URL"
:
"filesystem"
,
"SITE_TITLE"
:
"A website"
,
"SITE_TIMEZONE"
:
"UTC"
,
}
configuration_path
=
os
.
path
.
join
(
os
.
curdir
,
"configuration.yml"
)
if
os
.
path
.
exists
(
configuration_path
):
with
open
(
configuration_path
)
as
conf_file
:
conf_data
=
yaml
.
load
(
conf_file
)
for
key
,
value
in
conf_data
.
items
():
if
key
==
"development"
:
continue
site_key
=
f
"SITE_
{
key
.
upper
()
}
"
configuration
[
site_key
]
=
value
if
environment
==
Environment
.
DEVELOPMENT
and
"development"
in
conf_data
:
for
key
,
value
in
conf_data
[
"development"
].
items
():
site_key
=
f
"SITE_
{
key
.
upper
()
}
"
configuration
[
site_key
]
=
value
configuration
[
"SITE_UUID"
]
=
str
(
uuid
.
uuid5
(
uuid
.
NAMESPACE_URL
,
configuration
[
"SITE_URL"
])
)
if
"SITE_AUTHOR"
not
in
configuration
:
configuration
[
"SITE_AUTHOR"
]
=
f
"
{
configuration
[
'SITE_TITLE'
]
}
's author"
if
configuration
[
"SITE_URL"
]
==
"filesystem"
:
configuration
[
"SITE_URL"
]
=
f
"file://
{
os
.
path
.
abspath
(
output_path
)
}
/"
# Check that index file exists and copy it under the ./site folder
index_filepath
=
os
.
path
.
join
(
os
.
curdir
,
"index.html"
)
if
not
os
.
path
.
exists
(
index_filepath
):
...
...
@@ -183,36 +213,6 @@ def main(environment):
# If not, just stop here
return
# Load the configuration (it can be overidden by a configuration.yml file)
configuration
=
{
"SITE_URL"
:
"filesystem"
,
"SITE_TITLE"
:
"A website"
,
"SITE_TIMEZONE"
:
"UTC"
,
}
configuration_path
=
os
.
path
.
join
(
os
.
curdir
,
"configuration.yml"
)
if
os
.
path
.
exists
(
configuration_path
):
with
open
(
configuration_path
)
as
conf_file
:
conf_data
=
yaml
.
load
(
conf_file
)
for
key
,
value
in
conf_data
.
items
():
if
key
==
"development"
:
continue
site_key
=
f
"SITE_
{
key
.
upper
()
}
"
configuration
[
site_key
]
=
value
if
environment
==
Environment
.
DEVELOPMENT
and
"development"
in
conf_data
:
for
key
,
value
in
conf_data
[
"development"
].
items
():
site_key
=
f
"SITE_
{
key
.
upper
()
}
"
configuration
[
site_key
]
=
value
configuration
[
"SITE_UUID"
]
=
str
(
uuid
.
uuid5
(
uuid
.
NAMESPACE_URL
,
configuration
[
"SITE_URL"
])
)
if
"SITE_AUTHOR"
not
in
configuration
:
configuration
[
"SITE_AUTHOR"
]
=
f
"
{
configuration
[
'SITE_TITLE'
]
}
's author"
if
configuration
[
"SITE_URL"
]
==
"filesystem"
:
configuration
[
"SITE_URL"
]
=
f
"file://
{
os
.
path
.
abspath
(
output_path
)
}
/"
# List files from ./articles
articles
=
[]
for
filename
in
dir_tree
(
articles_path
):
...
...
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