I wanted to try out Sveltekit, and I wanted some way to easily create and track my code for the Advent of Code site. Thus this repo was born. I started on StackBlitz, but I just couldn't get over how bad the file tree works. I can never tell what directory a file is in because the file is indented more than two levels past directories.
To get github pages to work, I found these links, none of which was complete or perfect:
Things I had to do:
svelte.config.jsimport adapter from '@sveltejs/adapter-static';
const dev = process.argv.includes('dev');
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter({
fallback: 'index.html'
}),
prerender: { entries: [] },
paths: {
base: dev ? '' : '/sveltejs-kit-advent-of-code-2022',
},
}
};
export default config
adapter-staticIn /src/routes/+layout.svelte:
export const ssr = false;
I also had to add that to some other pages (i.e. about) which
are normally statically rendered too. about
was necessary for sure because it had commands specifically to
render it ahead of time, while others without specifics are
probably handled by default layout.
In /src/routes/+_page.js I did this:
export const prerender = false;
build-pages.sh script to run from git-bash.git commit -m "Building pages"
git checkout -B github-pages
pnpm run build
rm -rf docs
mv build docs
git add .
git commit -m "Github pages commit"
git push origin HEAD -f
git switch -
github-pages branch at current commitThis goes in /static/.nojekyll so it will be in our
/docs directory and tell github not to use it's jekyll
build tool since we have the site how we want.
In the repo settings on the left is a 'Pages' selection. I enabled it there and set the branch to 'github-pages' and the folder to '/docs'. For some reason the only folders that show are docs and root. Moving the build files to a docs directory enabled me to keep the build directory in .gitignore, so that was nice anway.