index

the sinister potion

antidisciplinary fun haver, cartoon mad scientist, objectpilled surrealist, universal collector, lover of perversion, spiritually nullo

art @unrealward


ChaiaEran
@ChaiaEran

So, I like Neocities. I think it's really great that someone out there is dedicated to providing free static HTML hosting, like the good old days.

You know what I don't like? Neocities' garbage HTML editor. It's an iframe in-browser, and it has none of the advantages that writing HTML in an actual IDE would have. Plus, it can kinda break if you refresh the page, and sometimes things revert, and--

It's a mess, is what I'm saying. Their entire backend GUI is kind of a mess. If you want to edit an HTML file in an actual IDE, you'd have to download the file, edit it, and re-upload it. Plus, it makes it kind of hard to keep a local backup of your site, you'd have to redownload the site every time you change something. And actually sending in the files via FTP is a no-go, since you have to pay $5 a month for that, and you want to use the service for free.

Well, what can you do? Use the CLI, that's what!

But Chaia! I don't like using the command line. I wanna use a GUI. I don't wanna type "neocities push /" every time I change something!

That's fine. If you can stomach using the CLI for ten minutes, then you'll have all the benefits of it without having to use it ever again!


EDIT
Thanks to @invis, I've learned you don't even need a GitHub account or a GitHub repo! Most of the steps are the same, and if you want to commit it to a repo, that's a good form of backup, so I'll split this post into two halves: With and without GitHub.
With GitHub

See, what we're going to do is pipe your website through a GitHub repo, and use a Git Hook to push it to Neocities whenever you update your website on GitHub. You just need a GitHub account, an IDE (I did this via Visual Studio Code, but you use whatever you like), Git, and Ruby. If your website is already on Neocities, what you do is go into their horrible GUI and click the "Download entire site" link. Unpack the zip into a dedicated folder, and that'll be the folder we make our GitHub repo. If you don't actually have a website yet, just make a folder.

From there, in either your IDE's terminal or a CLI, moved into your directory either way, you type:

git init
git add .
git commit -m "First commit"

Then you go into GitHub, create a new repository, and you copy the code from GitHub's website into your terminal:

git remote add origin <your github repo here>                    
>> git branch -M main
>> git push -u origin main

So, congrats, you've got a folder pushing to a GitHub repo. This part is pretty obvious to anyone who's used GitHub before, but I figured explicit instructions can't hurt.

But Chaia! What does this have to do with Neocities!? This is just pushing my site to GitHub, and I want my site on Neocities!

Well, my friend, that's where the Neocities CLI comes into play. If you've got Ruby installed, you type gem install neocities into your terminal, then run neocities list /, or one of the other subcommands, which will prompt you to log into your Neocities account on the Neocities CLI. It doesn't matter what the command is, the point is to login to the CLI.

Once you've done that, switch your terminal to Git Bash if you've been working in PowerShell, and copy the following lines, either from here or from the Neocities CLI page.

printf '#!/bin/sh\nneocities push .' >.git/hooks/pre-push && \
chmod u+x .git/hooks/pre-push

This will create a Git Hook that will push any changes to your site directly to Neocities whenever you push a commit to GitHub.

Oh, one last thing! Create a .gitignore file in your website folder that just contains this one line:

.git

Otherwise, the Neocities CLI will try to push the .git folder to your website, and we don't want that.

Aaaand you're done! You never have to touch the Neocities CLI or their horrible HTML editor again, you can just push to GitHub through your IDE and the hook will automatically push the changes through to Neocities!


Without GitHub

See, what we're going to do is use a Git Hook to push your website to Neocities whenever you update it. You just need an IDE (I did this via Visual Studio Code, but you use whatever you like), Git, and Ruby. If your website is already on Neocities, what you do is go into their horrible GUI and click the "Download entire site" link. Unpack the zip into a dedicated folder, and that'll be the folder we make our repo. If you don't actually have a website yet, just make a folder.

From there, in either your IDE's terminal or a CLI, moved into your directory either way, you type:

git init
git add .
git commit -m "First commit"

So, congrats, you've got a folder being used as a repo. This part is pretty obvious to anyone who's used Git before, but I figured explicit instructions can't hurt.

But Chaia! What does this have to do with Neocities!? This is just creating a Git repo, and I want my site on Neocities!

Well, my friend, that's where the Neocities CLI comes into play. If you've got Ruby installed, you type gem install neocities into your terminal, then run neocities list /, or one of the other subcommands, which will prompt you to log into your Neocities account on the Neocities CLI. It doesn't matter what the command is, the point is to login to the CLI.

Once you've done that, switch your terminal to Git Bash if you've been working in PowerShell, and copy the following lines, which I've modified to work without GitHub.

printf '#!/bin/sh\nneocities push .' >.git/hooks/pre-commit && \
chmod u+x .git/hooks/pre-commit

This will create a Git Hook that will push any changes to your site directly to Neocities whenever you commit your changes.

Oh, one last thing! Create a .gitignore file in your website folder that just contains this one line:

.git

Otherwise, the Neocities CLI will try to push the .git folder to your website, and we don't want that.

Aaaand you're done! You never have to touch the Neocities CLI or their horrible HTML editor again, you can just commit via your IDE and the hook will automatically push the changes through to Neocities!


You must log in to comment.

in reply to @ChaiaEran's post:

There used to be a really great guide about how to install Wordpress onto Neocities (that was largely about not installing it on Neocities itself, and more about setting your PC up to serve a Wordpress website that then auto-synced with Neocities after everything was baked out to static files).

Unfortunately, and worryingly, that site disappeared a little while ago. Thankfully it still exists on the internet archive. But that would in theory give you theme support and everything in a really roundabout, semi-complicated way, assuming it didn't get taken down for somehow being against Neocities TOS or something (considering the CLI page specifically mentions "static site generators", probably not).

Idk if anyone is going to see this, but I cannot login to the neocities CLI. Keeps giving me a "invalid credentials" despite giving the right credentials, which is disappointing because this sounded pretty neat otherwise.

Hi! Thanks for your post on this!! I wanted to comment here in case anyone had the same issue I did. I originally installed Ruby into a folder that had a space in the name, and I couldn't install neocities because of it. If you have an issue installing neocities, try reinstalling Ruby to the default location the installer suggests. I hope this helps someone. :)

Hi, thanks for the guide. As a complete beginner it's so cool to see a solution to the exact problem I was trying to solve. I was able to follow up until what I think is last step. Maybe I did the previous step wrong? Anyways if anyone is reading this, when I try to push to origin from the CMD or from the github desktop program I get this error message -

error: cannot spawn .git/hooks/pre-push: No such file or directory
error: waitpid for (NULL) failed: No child processes
error: failed to push some refs to 'link to my repo'

any advice would be appreciated
Thanks :)

Pinned Tags