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 content_api_key helper #21151

Merged
merged 4 commits into from
Oct 1, 2024
Merged

Conversation

cathysarisky
Copy link
Contributor

This very small helper adds {{contentkey}} to the collection of handlebars helpers available to theme creators.
This will make it easier for themes to access the content API key, without either requiring the user to get it from the integrations page and input it on the theme setting page or resorting to JavaScript to read it from one of the built-in script tag attributes -- both ugly workarounds.

@9larsons
Copy link
Contributor

9larsons commented Sep 30, 2024

@cathysarisky Have you tested a theme with this helper with gscan? Also could you expand on the use case? Helpers are meant to provide a means to interact with the content API w/o needing to do so directly.

@cathysarisky
Copy link
Contributor Author

@cathysarisky Have you tested a theme with this helper with gscan? Also could you expand on the use case? Helpers are meant to provide a means to interact with the content API w/o needing to do so directly.

Ohh... I bet I need to patch gscan, too. Will check, thank you.

I've had occasions where I wanted to access the API with something other than a built-in script, such as a 'dashboard' (with extra user data over in AWS) that needed to get the URLs of featured images given the post name.

Currently, some paid themes that use infinite scroll or client-side filtering of posts require the user to input their content API key as a theme setting. This will give them access to it directly in the theme instead. I've got a theme customization project to do this week where the client wants to be able to filter by multiple tags and authors. I definitely need to talk to the content API for that one, and its silly that the client needs to copy the API key from one place to another, or else I need to pull it out of the <script> tag from a built-in helper.

I'm also laying groundwork for being able to load alternate versions of the comments/portal/search code (beyond what is supported for self-hosters in config.[*].json), or any other external integration that needs access to the content API.

@cathysarisky
Copy link
Contributor Author

cathysarisky commented Oct 1, 2024

@cathysarisky Have you tested a theme with this helper with gscan?

No user-visible errors on uploading - apparently the check Ghost does on theme upload doesn't include checking for non-existent helpers.

Passes gscan. (Tested on gscan.ghost.org and also locally on a zip file that had {{content_api_key}} inserted into index.hbs)

@cathysarisky
Copy link
Contributor Author

I've added a test, and verified that gscan doesn't need updating. Thanks for your comments @9larsons !

Copy link
Contributor

@9larsons 9larsons left a comment

Choose a reason for hiding this comment

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

LGTM!

@9larsons 9larsons merged commit d8c4dfe into TryGhost:main Oct 1, 2024
21 checks passed
@thimiraonline
Copy link

How to use this and what are the uses of the helper?

@cathysarisky
Copy link
Contributor Author

How to use this and what are the uses of the helper?

I wrote a teeny blog post about it: https://www.spectralwebservices.com/blog/introducing-a-new-helper/

But basically, you put {{content_api_key}} in your .hbs code and it writes out the content API key. Useful if your theme has javascript that needs to use the api key.

I'd imagine using it for loading your own copy of portal or search or another integration, in combination with #21229.

@cathysarisky cathysarisky deleted the content_api_key branch November 10, 2024 15:42
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.

3 participants