-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add default metadata #40
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few changes, then can be merged
jssg/models.py
Outdated
data = {} | ||
json_data = "" | ||
content = StringIO() | ||
|
||
with settings.JFME_DEFAULT_METADATA_PATH.open() as f: | ||
for line in f : | ||
key, value = map(str.strip, re.split("[\s]", line, maxsplit=1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be interesting to reuse the comment possibility that is implemented in content descriptor (lines starting with a #
)
Look at model source code:
if line.startswith("#"):
continue # remove comment lines
I suggest to refactor/factorize parsing source code in a function.
It means in global parsing algorithm, replace:
if line.strip() == "": # ignore empty lines
continue
if line.startswith("#"): # ignore comment lines
continue
# Parse a metadata key value pair
# key, value = map(str.strip, line.split("", maxsplit=1))
import re
key, value = map(str.strip, re.split("[\s]", line, maxsplit=1))
# FIXME print("KEY {} : {} (line is: {})".format(key, value, line))
metadata[key] = value
with something like:
try:
key, value = parse_metadata_line(line)
metadata[key] = value
except EmptyLine:
[...]
except CommentLine as comment:
[...]
And reuse the algorithm/function for default metadata file parsing
jssg/settings.py
Outdated
@@ -52,7 +52,8 @@ | |||
JFME_POSTS_DIRS = [path / "posts" for path in JFME_CONTENT_DIRS] | |||
JFME_TEMPLATES_DIRS = [path / "templates" for path in JFME_CONTENT_DIRS] | |||
JFME_STATIC_DIRS = [path / "static" for path in JFME_CONTENT_DIRS] | |||
|
|||
JFME_DEFAULT_METADATA_DICT = {"slug": "index", } # The order of include is : JFME_DEFAULT_METADATA_DICT then JFME_DEFAULT_METADATA_PATH then page metadata | |||
JFME_DEFAULT_METADATA_PATH = BASE_DIR / "jssg" / "default_metadata.txt" # If a metadata is specified more than once, the last included is retained |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JFME_DEFAULT_METADATA_PATH
-> JFME_DEFAULT_METADATA_FILEPATH
3e8cf4d
to
8e01bea
Compare
Lets squash and merge @ClmntBcqt |
PR for issue #19