The neocities-ruby utility works great for managing your Neocities websites from the terminal unless you have multiple websites you’d like to manage this way, since the official utility does not provide any methods to have multiple accounts logged in simulateously.
Some searching around led me to this issue on Github which gave me enough information. It turns out that you can use this utility if you specify your website’s API key before running a command, as such:
1
NEOCITIES_API_KEY={Your API key} neocities
However, manually obtaining, storing and then retrieving your API keys every single time you want to do something with this utility is a bit of a pain. So, we’re going to do something about the last 2 points. You’re going to have to obtain your website’s API key manually. You can do this by simply logging into your Neocities account from the command line. The program will tell you your API key. For now, store this in a .txt
file in the root of your website’s directory.
Storing the API key as plaintext probably isn’t ideal so we’ll encrypt it using gpg
. We’ll do some symmetric encryption for our purposes as such:
1
gpg --symmetric api_key.txt
You’ll be prompted to enter a passphrase, which you’ll use to access the contents of this file whenever you decrypt it.
Finally, let’s create a shell script that’ll let us use the rest of the neocities program as usual. The only caveat with this is that you’ll have to wrap your commands in a string, but the rest of the functionality is the same.
|
|
Things to note:
- line 2 checks if you entered more than 1 argument.
- i.e. if you use the script as such:
./neocities.sh neocities info
you’ll get an error. - Use it instead as such:
./neocities.sh 'neocities info'
.
- i.e. if you use the script as such:
- line 6 decrypts
api_key.txt.gpg
and stores the API key in a variable, which it uses in the following command.
Repeat for each of your Neocities websites, and everytime you want to do something with it from the command line, you can use this script!