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

Register additional static content #2804

Open
3 tasks done
bviefhues opened this issue Oct 5, 2020 · 10 comments
Open
3 tasks done

Register additional static content #2804

bviefhues opened this issue Oct 5, 2020 · 10 comments
Assignees

Comments

@bviefhues
Copy link

  • I have searched the issues (including closed ones) and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.
  • I am willing to lend a hand to help implement this feature.

Feature Request

Expose a method or a function for usage by plugin authors for registering static content, for processing with all "pelican magic".

This should allow plugin authors to implement functionality similar to what {static} or {attach} does in the built-in readers, including:

  • specifying a source_path,
  • copying file to output,
  • accessing the target URL.
@stale
Copy link

stale bot commented Dec 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your participation and understanding.

@stale stale bot added the stale Marked for closure due to inactivity label Dec 4, 2020
@kdeldycke
Copy link
Contributor

kdeldycke commented Dec 6, 2020

That would be great. I had the exact same issue as I was looking for my theme to automatically adds a couple of assets (favicons in this case) at the root of the generated site.

I hacked my way into Pelican internals and hook a signal to register my assets as static files one by one. See my hack at:
https://github.com/kdeldycke/plumage/blob/ebdc9a5ece646fdc8a30518befdd3092322c9458/plumage/__init__.py#L73-L107

@stale stale bot removed the stale Marked for closure due to inactivity label Dec 6, 2020
@bviefhues
Copy link
Author

I have a working solution, after figuring out how the pelican internals work with each other. This essentially injects my static files into Pelican's static file processing.

  1. Register my reader with signals.readers_init.connect
  2. Register a helper function with signals.static_generator_finalized.connect
  3. In the reader, add the static content as custom keys in the metadata dict.
  4. In the helper function get the articles metadata list from the generator context, loop through list and for each custom key:
  • Format source_path, save_as and url for the static content file
  • Create a new metadata dict by copying the article metadata dict
  • Create a new Static object instance
  • Append Static object to generator context via generator.context['staticfiles'].append()
  • Add custom key to article metadata for url (to make accessible in jinja2)
  • setattr same key on article instance (pelican has generated attributes from the metadata already and this needs to be added)

This makes the StaticGenerator processing the added static files

@kdeldycke
Copy link
Contributor

Thanks @bviefhues for the feedback! It really looks like something similar to my solution. Do you have code to share so we can compare? We might create a common utility method to cover that case and eventually propose it to Pelican project.

@avaris
Copy link
Member

avaris commented Dec 7, 2020

Commenting here for the record, {static} or {attach} is not handled in Reader stage. They are dealt with after reader processes the file and a Content object is created, which is essentially the generator stage. So, yes, a mixed approach is necessary.

@bviefhues
Copy link
Author

@kdeldycke here is a reader I wrote for a small Pelican-powered site: ExifReader. Built for a rather specific use case. We should aim for a more generic solution.

@stale
Copy link

stale bot commented Feb 8, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your participation and understanding.

@stale stale bot added the stale Marked for closure due to inactivity label Feb 8, 2021
@justinmayer
Copy link
Member

Hi @bviefhues. Would you be willing to help implement a more generic solution, as you proposed?

@stale stale bot removed the stale Marked for closure due to inactivity label Feb 11, 2021
@bviefhues
Copy link
Author

@justinmayer definitelly would like to help. Least i can do is use my tiny website as a testbed.

Also willing to do changes on Pelican itself, if we come to a robust idea on how to implement.

@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your participation and understanding.

@stale stale bot added the stale Marked for closure due to inactivity label Jun 2, 2021
@stale stale bot removed the stale Marked for closure due to inactivity label Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants