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 :update-article-fn to customize parsed page/.. #130

Merged
merged 1 commit into from
Dec 10, 2019
Merged

Add :update-article-fn to customize parsed page/.. #130

merged 1 commit into from
Dec 10, 2019

Conversation

holyjak
Copy link
Contributor

@holyjak holyjak commented Dec 9, 2019

Allow users to supply a function run on every parsed page/post to
update it.

Example uses:

  • support for a custom :slug metadata in a post to override the defaul
    uri
  • post-process the HTML to add self-links to every heading

NOTE

I struggled to find a good name for "post or page". In the end I have fallen back on the HTML standard and adopted the name it uses for the "main content", i.e. "article". Any better ideas?

NOTE 2

Notice that while extend-params-fn runs very late in the process, this runs very early so it can modify the base data used to create the various site data such as posts and posts-by-tags, while extend-params-fn would need to modify all the places where e..g a particular post is used.

@lacarmen
Copy link
Member

lacarmen commented Dec 9, 2019

I have fallen back on the HTML standard and adopted the name it uses for the "main content", i.e. "article". Any better ideas?

Let's leave it at that, naming is hard 😆.

Will you update the docs site again? A couple of examples that illustrates the flexibility/power this adds would be great!

@holyjak
Copy link
Contributor Author

holyjak commented Dec 9, 2019 via email

@holyjak holyjak changed the title Add :update-article-fn to customize parsed page/.. WIP Add :update-article-fn to customize parsed page/.. Dec 9, 2019
@holyjak
Copy link
Contributor Author

holyjak commented Dec 9, 2019

DON'T MERGE pls

I realized it would be better to pass also config to the function so I will add that (so that we have access e.g. to blog-prefix in in)

Allow users to supply a function run on every parsed page/post to
update it.

Example uses:

- support for a custom `:slug` metadata in a post to override the defaul
  uri
- post-process the HTML to add self-links to every heading
@holyjak holyjak changed the title WIP Add :update-article-fn to customize parsed page/.. Add :update-article-fn to customize parsed page/.. Dec 10, 2019
@holyjak
Copy link
Contributor Author

holyjak commented Dec 10, 2019

Ready to merge.

I have updated it to send also the config to the function and to make it possible to return nil from the fn to exclude the article from the blog.

@holyjak
Copy link
Contributor Author

holyjak commented Dec 10, 2019

See cryogen-project/cryogen-docs#27 for the corresponding docs change.

@lacarmen
Copy link
Member

Looks great -- good call on passing in the config and returning nil to exclude articles :) Will push out new versions now!

@lacarmen
Copy link
Member

And thank you again for all the great features you've been adding!

@lacarmen lacarmen merged commit b095526 into cryogen-project:master Dec 10, 2019
([overrides]
([{:keys [extend-params-fn update-article-fn]
:or {extend-params-fn (fn [params _] params)
update-article-fn identity}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this can't be identity because it's called with 2 args, but I can fix it :)

@holyjak
Copy link
Contributor Author

holyjak commented Dec 10, 2019 via email

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.

None yet

2 participants