Hi all,
I am trying to generate a static site from my instance of Ghost to host it on CloudFlare Pages. The tool that makes most sense for my use case ( nothing fancy, just copy the HTML, CSS, JS and images ) so far seems to be gssg. The best thing about it is that it can update all the URIs like:
https://dev.site.com
to
https://site.com/en
The only problem I am experiencing with it is that it does not fetch the ./assets and the ./content folder, respectively resources are missing. I can add them manually, but I prefer something that can do it in one go.
After reading through the forum the Ghost recommendation for SSG seems to be Eleventy. It looks to be an overkill from what I am reading for exporting only the frontend with updated links.
Has someone managed to get gssg to fetch all the resources ? Or I need to consider an alternative ?
1 Like
I use gssg, and it seems to fetch assets fine except the ones that are lazy loaded with JavaScript; but the paths may not be right.
The exact approach will depend on your theme. I have a bash script that runs gssg, and then pulls in the assets, and runs a few fixes. For my Laminim theme, I pull in the lazy-loaded CSS and fonts with:
# Fix missing files
cp /var/www/ghost/content/themes/laminim/assets/css/defer.min.css /var/www/gssg-laminim/laminim-ghost-theme/assets/css/defer.min.css
cp -r /var/www/ghost/content/themes/laminim/assets/fonts /var/www/gssg-laminim/laminim-ghost-theme/assets/fonts
And fix a few paths with:
# Fix RSS
find . -type f | xargs sed -i 's/\/rss\//\/rss\/rss\.xml/g'
find . -name "rss" -exec mv {}/index.html {}/rss.xml \;
find . -type f | xargs sed -i 's|\/author\/\([^/]*\)\/rss"|\/author\/\1\/rss\/rss\.xml"|g'
# Fix assets path
find . -type f | xargs sed -i "s|'\/assets|'https:\/\/laminim\.curiositry.com\/assets|g"
1 Like
Thanks @curiositry , the idea is much appreciated. Your approach actually did the trick for me. I put together the following gssg wrapper that works for my modification of the Solo theme:
#!/bin/bash
workdir=static
dev_site=https://dev.site
prod_site=https://prod.site
rm -rf $workdir
gssg --domain $dev_site --url $prod_site --dest $workdir &&
cp -r /var/www/oliverkostoff/content/images ${workdir}/content/ &&
cp -r /var/www/oliverkostoff/content/themes/solo-dark/assets/built/ ${workdir}/content/ &&
cp -r /var/www/oliverkostoff/content/themes/solo-dark/assets/fonts/ ${workdir}/content/ &&
cp -r /var/www/oliverkostoff/content/public/ ${workdir}/content/ &&
find ${workdir}/ -type f -print0 | xargs -0 sed -i 's|/assets/built/screen.css?v=[a-zA-Z0-9]*|/bg/content/built/screen.css|g' &&
find ${workdir}/ -type f -print0 | xargs -0 sed -i 's|/public/cards.min.css?v=[a-zA-Z0-9]*|/bg/content/public/cards.min.css|g' &&
find ${workdir}/ -type f -print0 | xargs -0 sed -i 's|/public/cards.min.js?v=[a-zA-Z0-9]*|/bg/content/public/cards.min.js|g' &&
find ${workdir}/ -type f -print0 | xargs -0 sed -i 's|/assets/built/main.min.js?v=[a-zA-Z0-9]*|/bg/content/built/main.min.js|g'
#This line pushes to PROD Cloudflare Pages project
#wrangler pages deploy $workdir --branch main
I think parsing the correct blog Post URLs, as well as some basic search functionality in JS are the only remaining items. Will update that wrapper when I get to it.
Once again, thank you
1 Like