-
Notifications
You must be signed in to change notification settings - Fork 9
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
Cover Image Generator #8
Conversation
✅ Deploy Preview for gridsome-geek-blog ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Hi @neilherbertuk I appreciate your work, this is cool feature. I have few suggestions
Great work 🙌 ! Thanks for PR |
Thanks for the comments @xqsit94. Happy to make changes as needed just need some clarity.
Could you expand on this a little? Do you mean take the file name, parse and use that as the text in the image? That might not be that desired and very hard to parse. If your filename is
I get where you are coming from with this, there could easily be a file clash between posts. However, this would require updating the post md file from the function generating the cover image to add the exact thumbnail filename thats been generated. I'm not comfortable making changes to the user's content. Perhaps it would be better to just match the name of the post so in my example above
Absolutely! Will look at adding that and
I understand the desire to surpress the error mentioned with |
Add featute flag to env Remove default filename if thumbnail front matter not set
I've added the feature flag as suggested. I've also added some docs to cover use of that feature. I've changed the code so it does not generate a cover image if a Could do with some guidance from my last reply. |
Change cover_title snakecase to coverTitle camelCase Change single quotes to double quotes for consistency
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
@xqsit94 I've cleared all but 1 "code smell" from sonar. Not willing to clear the security hotspots as these are non-issues, these can be marked as safe on sonarcloud by yourself or I can add //nosonar at the end of each line that uses |
Yes @neilherbertuk I have marked it as safe. |
@xqsit94, I really like geek-blog. Glad I can contribute! |
I've created a blog post cover generator using node-html-to-image and tinycolor2 and based loosely on https://terabytetiger.com/lessons/generated-blog-post-cover-images-with-gridsome/. I've tested this with netlify and it does generate covers as expected. However, if you leave this to be run by a pipeline, your cover images will change unpredictably each time you deploy. It would be best to generate them locally and commit the generated covers to your git repo.
Each time you run
yarn develop
it checks to see if a cover image needs to be generated. It checks all Posts for athumbnail
frontmatter entry, if one does not exist the post filename is used postfixed with .png. If the cover image file does not exist it proceeds to generate a cover image based on the design already used for the cover images provided with geek-blog. If you wish to use something shorter/different from the posttitle
add acover_title
frontmatter entry. If acover_title
entry exists it will use that, otherwise it will use thetitle
entry.If you wish to regenerate a cover, simply delete the existing one and re-run
yarn develop
.This works by adding an entry in the
gridsome.server.js
file and a function withinsrc/functions/generate-cover.js
. Out of the box the cover generator will create a completely random colour each time it runs. If you want to define a selection of colours to pick from, update the colours array withingenerate-cover.js
and switch over the comments at the bottom of the following section:This may need some tweaking and thoughts to whether this should be a feature that can be turned off using an environment variable? Also whether to include the generated covers in the released version or stick with the existing?