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
61b3d16d
Commit
61b3d16d
authored
Jan 11, 2019
by
berumuron
Browse files
imp: Improve site URL support
parents
fa2f5f47
af29c5bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
61b3d16d
...
...
@@ -186,7 +186,29 @@ timezone: Europe/Paris
```
You can declare as many variables as you want, they all will be accessible in
the article template, uppercased and prepended by `SITE_`.
the article template, uppercased and prepended by `SITE_`. `url` can be set to
`filesystem` for development (it will generate paths to the output directory).
If you want to use a different configuration in development, you can specify
different options under a `development` section:
```
yaml
url: http://my-website.org/
title: My website
author: Dale Cooper
timezone: Europe/Paris
development:
url: filesystem
```
By default, `boop.py` command generates the website with production
configuration. To use the development one you should pass the `--development`
argument:
```
console
$ boop.py --development
```
You might find yourself limited by the article-only system. If you want to
create additional pages, just put HTML files under a `pages` folder. The
...
...
boop.py
View file @
61b3d16d
...
...
@@ -8,6 +8,7 @@ import locale
import
yaml
import
datetime
import
uuid
from
enum
import
Enum
import
markdown
import
pytz
...
...
@@ -19,6 +20,11 @@ import boopfeed
locale
.
setlocale
(
locale
.
LC_ALL
,
""
)
class
Environment
(
Enum
):
DEVELOPMENT
=
1
PRODUCTION
=
2
class
ProgramError
(
Exception
):
"""Exception raised during the program execution.
...
...
@@ -127,7 +133,7 @@ def mkdirs_for_file(filepath):
os
.
makedirs
(
path
,
exist_ok
=
True
)
def
main
():
def
main
(
environment
):
# Make sure ./site folder is empty
output_path
=
os
.
path
.
join
(
os
.
curdir
,
"site"
)
if
os
.
path
.
isdir
(
output_path
):
...
...
@@ -179,7 +185,7 @@ def main():
# Load the configuration (it can be overidden by a configuration.yml file)
configuration
=
{
"SITE_URL"
:
"
http://localhost
"
,
"SITE_URL"
:
"
filesystem
"
,
"SITE_TITLE"
:
"A website"
,
"SITE_TIMEZONE"
:
"UTC"
,
}
...
...
@@ -189,14 +195,23 @@ def main():
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
=
[]
...
...
@@ -276,8 +291,12 @@ def main():
if
__name__
==
"__main__"
:
environment
=
Environment
.
PRODUCTION
if
len
(
sys
.
argv
)
==
2
and
sys
.
argv
[
1
]
==
"--development"
:
environment
=
Environment
.
DEVELOPMENT
try
:
main
()
main
(
environment
)
print
(
"Boop!"
)
except
ProgramError
as
e
:
print
(
e
.
args
[
0
],
file
=
sys
.
stderr
)
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