Sharing Shortcodes #103
Replies: 2 comments 1 reply
-
Very new to building with Quire so I'm probably off-course. |
Beta Was this translation helpful? Give feedback.
-
@daniel-keller I’m really glad you brought this up! It’s something we’ve been thinking about ourselves but haven't yet resolved. And apologies for the length of my reply here, but the question really gave me the chance to think through this and document it all in more detail than I've done before. And my reply is more speculation than full-fledged answer but I'd love to get feedback from the community. I'm also hoping @mphstudios @workergnome and @hbalenda will have a chance to weigh in as well. The idea of publishing it as an npm package is interesting, even with the challenges you point out. However, I’m afraid that approach might be out of scope for other community members who would be interested in sharing their own shortcodes or other custom work they’ve done in Quire. Ideally I'd like to come up with a consistent solution that we can promote across the board. My thinking about it has been along the lines of what @emptyhut suggested in their comment (:clap:), adding things in as additional themes. This is what Hugo calls theme components, which need not be entire themes but can be as small as a single shortcode. @theNewDynamic (@budparr and @regisphilibert) have linked to some examples in their Awesome Hugo repo. Where I run into trouble with these is from what I’m seeing, any CSS and JS involved has been inserted in the HTML file of the shortcode or partial itself, either inline or called as an external file with a Here’s my current idea: Let’s say we want to add a theme component called theme:
- custom-shortcode
- default Let’s say the files looks something like this:
Here we’re establishing a very simple structure and filenaming convention, namely that the CSS and JS files of a theme component live in the static directory in {{ range .Site.Themes -}}
{{- $cssPath := printf "%s/%s%s" "css" . ".css" -}}
{{- $hugoPath := printf "%s/%s/%s/%s" "themes" . "static" $cssPath -}}
{{- if fileExists $hugoPath -}}
<link rel="stylesheet" href="{{ $cssPath | relURL }}">
{{ end -}}
{{ end }} This would loop through the list of themes in <link rel="stylesheet" href="/css/custom-shortcode.css">
<link rel="stylesheet" href="/css/default.css"> The one additional thing we’d have to do is re-write this a little to reverse the order the links are added (I just didn’t do it here for clarity’s sake). In Hugo theme components, files in the top-most listed component will override others below it. Similarly, we’d want the CSS from that component to override any that was in other components below it, and so that CSS file should actually need to be linked to last. HOWEVER, the big problem here is that The best alternative I’ve come up with is to use Hugo’s {{ range (readDir "themes") -}}
{{- $cssPath := printf "%s/%s%s" "css" .Name ".css" -}}
{{- $hugoPath := printf "%s/%s/%s/%s" "themes" .Name "static" $cssPath -}}
{{- if fileExists $hugoPath -}}
<link rel="stylesheet" href="{{ $cssPath | relURL }}">
{{ end -}}
{{ end }} This works EXCEPT that the links to the CSS files will be arbitrarily added in the order that they occur in the directory (alphabetically), and so we run into the problem of CSS from a theme component like And this is where I’ve gotten stuck. Maybe there's something in Hugo that I'm missing. Or, one idea is to establish our own custom parameter but then we still have to list the same things under params:
quireComponents:
- custom-shortcode
- default I'm not sure. Maybe the first question though is if this idea of theme components is the best solution to the question of how community members package and share custom Quire work? |
Beta Was this translation helpful? Give feedback.
-
We've received several requests to shar the shortcodes we've created for our "Masterpieces from the Clowes Collection" catalog (in development) but I'm not sure of the best way to do this. From what I've found this isn't a common practice in the Hugo community (probably b/c of the challenges I'm going to discuss below).
Hugo requires your shortcode files to be in specific locations outside of your dependencies directory so installing the shortcodes as an npm package won't work out of the box. I can use npm's postinstall script to move the shortcode's html/css/js files to the appropriate file locations as defined by Quire's file structure but I risk overwriting files that already exist. I don't see embedding the css/js in the shortcode itself as an option since you lose the benefit of css/js preprocessing and transpiling.
Right now I'm leaning towards creating an npm package and just providing detailed instructions on where to copy the files and how to plug the js and css into the Quire defined application.js and _all.scss.
Anyone have ideas on the best way to package and share shortcodes?
Beta Was this translation helpful? Give feedback.
All reactions