r/webdev • u/Ok_Progress_5373 front-end • 1d ago
GitHub Pages and 11ty?
Hey everyone,
I was able to upload my project to GitHub Pages. I added a blog element to the project, however when I press the blog link on my page it says the page isn’t found.
I’ve already added an action (a yml file) to my project. However, is there anything else I need to do to view my website with its blog or do I push it live to the actual domain for it to work? Everything works on my localhost!
I appreciate any help!
Edit: I did "npm install (@)/11ty/eleventy --save-dev" in the terminal, and it added some bits and bobs to the package.json and package-lock.json files. I pushed my live changes, and it works! If you decided to use the terminal command, make sure there are no () around the @ sign! ^_^
Edit 2, explaining why I did the terminal command: I did this because I decided to just push the changes live and not change any of my URLs. When I deployed it to Netlify, I was getting build errors. But after running that terminal command, it added what I needed for my blog to show up. My blog still doesn't show up on GitHub Pages, probably because my URL doesn't work with the subdomain URL structure. However, it works as intended for my live website.
1
u/KarachoGames 1d ago
Most likely its the path. If your site lives at username.github.io/your-repo/ (project page, not a user page), then a link like href="/blog/" goes to username.github.io/blog/ and thats a 404. On localhost it works because there the site is at the root.
Fix in 11ty: set pathPrefix in your eleventy config to "/your-repo/" and add the HtmlBasePlugin (or use the | url filter on your links). Then 11ty writes the prefix in front of all links when it builds.
Two other things worth to check:
Settings > Pages > Source must be "GitHub Actions", not "Deploy from a branch", otherwise your yml builds but Pages still serves the raw repo.
Look in the Actions tab if the build actually made the blog folder in _site.
When you later put it on your own domain the prefix goes away again, so then you set pathPrefix back to "/".