How does Jekyll use automatic synchronization script to push to Neocities free website space?

💻Learn how to use a Jekyll auto-sync script✨ to quickly push to Neocities space🎉

🚀Get started quickly! Use Jekyll automatic synchronization script ✨Push your website to Neocities free space 🏡, no more manual operations! Detailed steps 📋 + practical tips 💡 allow you to easily publish your website 🌐. Click to view the complete tutorial🔍 and experience the convenient operation immediately! 🎉

The basic idea of ​​using a script to synchronize static websites generated by Jekyll to Neocities is as follows:

Setting up a Jekyll website : First, you need to build your Jekyll website.

  • runjekyll buildcommand, will be in_site/Generate static files in the directory.

Using the Neocities CLI: Install the Neocities command-line tools, a Ruby gem.

  • It can be installed by running the following command:
gem install neocities
  • Using the batch script automatic synchronization method, the local static website directory can be pushed to Neocities synchronously.

How to solve ERROR: Could not find a valid gem 'neocities'?

If the command is run:

gem install neocities

The following error occurs:

ERROR: Could not find a valid gem 'neocities-jekyll' (>= 0), here is why:
     Unable to download data from https :// gems. ruby-china .com/ – SocketError: FaiThis led to the opening of a TCP connection to gems.ruby-china.com:443 (getaddrinfo: Unknown host). (https://gems.ruby-china.com/specs.4.8.gz)

The reason for this error is that the RubyGems source https://gems.ruby-china.com/ you are using cannot be connected.

This may be due to several reasons:

  1. Internet problem: You may not be connected to the Internet, or your Internet connection may be unstable.
  2. RubyGems source issues: The RubyGems source may be down or under maintenance.
  3. Firewall issues: Your firewall may be blocking RubyGems from connecting to the source.

Here are some solutions to this problem:

1. Check network connection

First, make sure you are connected to the internet and can access other websites. You can open a web browser and visit some websites, such as https://www.chenweiliang.com/ or https://www.etufo.org/ , to test your connection.

2. Change RubyGems source

If your network connection is normal, you can try changing the RubyGems source.

You can change the RubyGems repository to the official repository using the following command:

gem source -a https://rubygems.org/

3. Then, try installing the Neocities plugin again:

gem install neocities

How does Jekyll use automatic synchronization script to push to Neocities free website space?

How does Jekyll use automatic synchronization script to push to Neocities free website space?

Write a synchronization script:due toneocities pushExisting files will not be deleted, you will need to write a script to synchronize the files.

This script can compare local _site/Directories and files on Neocities, delete files on Neocities that no longer exist locally.

Here is a simple Windows batch script to automatically synchronize files, showing how to perform the above steps:

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

REM 设置Neocities API密钥环境变量
set NEOCITIES_API_KEY=%NEOCITIES_API_KEY%

REM 检查API密钥是否已经设置
IF "!NEOCITIES_API_KEY!" == "" (
echo Neocities API key is not set in the environment variables.
goto error
)

REM 定义本地静态网站目录
set LOCAL_SITE_DIR=d:\Jekyll\site1\_site

REM 删除不在目录中的站点文件(小心!)
neocities push --prune "%LOCAL_SITE_DIR%"

:sync
REM 同步本地静态网站到Neocities
echo Syncing local site to Neocities...
neocities push "%LOCAL_SITE_DIR%"

echo Sync complete.
goto end

:error
echo There were errors during the script execution.

ENDLOCAL

REM defines local static website directory
set LOCAL_SITE_DIR=d:\Jekyll\site1\_site

  • Change the above script d:\Jekyll\site1 Change it to your folder name.

Instructions

  1. Save this script as a .bat file, e.g. sync_to_neocities.bat.
  2. Set the API key as a system environment variable NEOCITIES_API_KEY, and reference it in your script (your API key can be found in your Neocities account settings).
  3. Make sure the Neocities CLI tool is installed and the neocities command can be used from the command line.
  4. Open a command prompt (cmd) or PowerShell window.
  5. Navigate to the directory where the script is located.
  6. Run the script:sync_to_neocities.bat

How to set Neocities API key environment variable?

  1. Open the Windows Control Panel.
  2. Click "System and Security."
  3. Under System and Security, click System.
  4. In the System Panel, click Advanced system settings.
  5. In the System Properties dialog box, click the Environment Variables button.
  6. In the Environment Variables dialog box, click the New, Edit, or Delete button to add, edit, or delete system or user variables.
  7. Create a new one in "System Variables"NEOCITIES_API_KEY” variable and set the variable value to your API key.

How to run the script?

Open command prompt (cmd).

Navigate to the directory where the script is located, for example:

cd /d d:\Jekyll\site1

Run the script:

sync_to_neocities.bat

Neocities upload command instructions

Neocities Push

|\—/|
| o_O | Neocities
\_^_/

Push – Recursively upload local directories to your Neocities site

example:

  • $ neocities push .Recursively upload the current directory.
  • $ neocities push -e node_modules -e Secret.txt .Exclude certain files from push
  • $ neocities Push --no-gitignore .Don't use .gitignore to exclude files
  • $ neocities Push --dry-run .Just show what you want to upload
  • $ neocities Push --prune .Delete site files that are not in the directory (be careful!)

Comment

Your email address will not be published. Required fields are marked with * .

Scroll to Top