Skip to content
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

Merged
merged 5 commits into from
Jul 24, 2024
Merged

Add default metadata #40

merged 5 commits into from
Jul 24, 2024

Conversation

ClmntBcqt
Copy link
Contributor

PR for issue #19

@ClmntBcqt ClmntBcqt requested a review from lebouquetin July 18, 2024 09:17
Copy link
Member

@lebouquetin lebouquetin left a 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))
Copy link
Member

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
Copy link
Member

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

@ClmntBcqt ClmntBcqt force-pushed the feat__19_add_default_metadata branch from 3e8cf4d to 8e01bea Compare July 24, 2024 08:26
@ClmntBcqt ClmntBcqt requested a review from lebouquetin July 24, 2024 08:31
@lebouquetin
Copy link
Member

Lets squash and merge @ClmntBcqt

@ClmntBcqt ClmntBcqt merged commit a94e569 into main Jul 24, 2024
2 checks passed
@ClmntBcqt ClmntBcqt deleted the feat__19_add_default_metadata branch July 24, 2024 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants