Blog Server with Fediverse
中文文档 | English
A simple blog server. Based on Node.js, Next.js and SQLite.
The project name has not been determined yet, maybe you can give me some suggestions?
Features
- Support WebFinger, ActivityPub Federated comment system (disabled by default)
- Support GFM (GitHub Flavored Markdown)
- Online editing articles
- React Server Components
- Multi-language support (based on
next-intl
) - Docker quick deployment
- Custom website in the admin panel
- Online upload custom cover
- Global search
There are many features that have not been implemented yet, but it has reached the level of normal use. Suggestions and code contributions are welcome. The database part should not have backward compatibility issues, but the configuration file and environment variables may change.
Note: The master branch is the development branch, which may have problems such as unable to run, incompatible database changes, etc. Please use the Release version.
Regarding memory usage, due to the use of Node.js and no special optimization
(lazy + don't know + for simple deployment), it is naturally incomparable with
compiled languages. About 220MB in idle state, and about 20MB additional usage
when rendering an article with 30,000 words containing a large number of mathematical
formulas (only the first rendering, less than 1 second), so a blog with small
traffic generally uses 300MB.
After several radical optimizations of the rendering logic, both memory usage and rendering speed have been significantly improved, and the loss caused by real-time rendering can be ignored.
Quick Start
Run using Docker
Download docker-compose.yml
to your local
wget https://raw.githubusercontent.com/skyone-wzw/blog-server/master/docker-compose.yml
Edit environment variables (no need to modify for local testing)
DATABASE_URL
: Database file path, default isfile:./data/data.db
DATA_DIR
: Data directory, default is./data
SECRET_KEY
: AES encryption key, required, a string of length 32SECRET_IV
: AES encryption vector, required, a string of length 16AUTH_EMAIL
: Backend login email, requiredAUTH_PASSWORD
: Backend login password, required
docker-compose up -d
Open your browser and visit http://localhost:3000
.
Download precompiled version from Release
Download the latest precompiled version from Release. Unzip to any directory, synchronize the database and start the server:
npm prisma generate
npm run start
Open your browser and visit http://localhost:3000
.
Build from source
Clone the repository and install dependencies
git clone https://github.com/skyone-wzw/blog-server.git --depth=1
cd blog-server
npm install
Build the project
npx prisma generate
npm run run patch-font
npm run build
Create work dir and copy the necessary files
cp -r .next/standalone build
cp -r .next/static build/.next/static
cp -r public build/public
Then flow the steps in Download precompiled version from Release.
Configuration
There are two configuration files: .env
and data/config.json
. Other custom content
(such as website title, logo, author, etc.) can be set in the website backend.
Environment variables
You can set the data directory and database file path in the .env
file
(located in the project root directory), the environment variables written
to this file will be automatically loaded, of course, setting environment
variables directly is also possible.
# Required
DATABASE_URL="file:./data/data.db"
# Optional, default is ./data
DATA_DIR=./data
# Optional, you can set it in data/config.json
SECRET_KEY="12345678123456781234567812345678"
SECRET_IV="1234567812345678"
AUTH_EMAIL=abc@example.com
AUTH_PASSWORD=123456
Configure file
The data/config.json
file (the data directory is specified by the environment variable DATA_DIR
) is an alternative to environment variables. If you don't want to use environment variables, you can also choose a configuration file. But in any case, you must set the DATABASE_URL
environment variable.
Note: Environment variables take precedence over configuration files.
Refer to the following example, all options are optional
{
"auth": {
"email": "",
"password": ""
},
"secret": {
"key": "",
"iv": ""
},
"dir": {
"data": "./data",
"image": "./data/post",
"cover": "./data/cover",
"random": "./data/cover/random",
"custom": "./data/custom",
"cache": "./data/cache"
}
}
Environment variables take precedence over configuration files, and environment variables are read after loading the configuration file, but
DATA_DIR
is an exception because the location of the configuration file is also determined byDATA_DIR
.In short, the configuration file is located at
$DATA_DIR/config.json
, and environment variables take precedence over the configuration file.
Configuration item description
In environment variables:
DATA_DIR
: Data directoryDATABASE_URL
: Database file path, format isfile:/path/to/database.db
SECRET_KEY
: AES encryption keySECRET_IV
: AES encryption vectorAUTH_EMAIL
: Backend login emailAUTH_PASSWORD
: Backend login password
In configuration file:
auth.email
: Backend login emailauth.password
: Backend login passwordsecret.key
: AES encryption keysecret.iv
: AES encryption vectordir.data
: Data directory, it is recommended to use the environment variableDATA_DIR
dir.image
: Image directorydir.cover
: Cover directorydir.random
: Random cover directorydir.custom
: Custom directorydir.cache
: Cache directory
Article cover background image
By default, the article cover background image is random. You can put your image
in the data/cover/random
directory. The image with the path data/cover/[slug].(jpg|png|webp)
will be used as the cover of the corresponding article. The specific matching rules are as follows:
- Find
data/cover/[slug].(jpg|png|webp)
, if it exists, use it, if there are multiple formats, randomly select one - Find
data/cover/random/
, if it exists, randomly select one - If no image is found when the program starts, create
data/cover/random/default.webp
as the default image
More Previews
License
3 comments from the FederationSearch in the Federation
https://example.com/post/blog-server-en
From @skyone@social.silicon.moe
Commented at December 27, 2024
@skyone@blog-server.akk.moe Interesting idea, I'm trying it out!
Skyone
From @skyone@social.silicon.moe
Reply to @skyone@social.silicon.moe
Commented at December 27, 2024
@skyone@blog-server.akk.moe cool! more test:
```js
console.log("more test");
```
DetailsReply