网站构建及迁移记录

  大童  |   on Tuesday, February 20, 2024  |  2689   |  6 minutes

网站构建及迁移记录

主题模版

使用hugo框架,模版主题参见hugo-theme-cleanwhite 部署过程中,在原作者基础上做了一些修改记录。

$ mkdir themes  
$ cd themes  
$ git clone https://github.com/zhaohuabing/hugo-theme-cleanwhite.git  

模版使用,只要把主题放在web_home_path/themes目录下。 比如,把hugo-theme-cleanwhite放到/Users/gavin/myweb/themes目录下。

站内搜索Algolia

$ npm init  
$ npm install atomic-algolia --save  

Next, open up the newly created package.json, where we’ll add an NPM script to update your index at Algolia. Find “scripts”, and add the following:

"algolia": "atomic-algolia"  

Algolia index output format has already been supported by the CleanWhite theme, so you can just build your site, then you’ll find a file called algolia.json in the root, which we can use to update your index in Algolia.

Generate index file:( ⚠️ 发布到public目录下。hugo本身可以作为web server,这时候不需要用运行hugo发布。)

$ hugo  

Create a new file in the root of your Hugo project called .env, and add the following contents:

ALGOLIA_APP_ID={{ YOUR_APP_ID }}  
ALGOLIA_ADMIN_KEY={{ YOUR_ADMIN_KEY }}  
ALGOLIA_INDEX_NAME={{ YOUR_INDEX_NAME }}  
ALGOLIA_INDEX_FILE={{ PATH/TO/algolia.json }}  
==> ️以上出错,“{{会被当成内容读入可选择用双引号或不用  
ALGOLIA_APP_ID =  YOUR_APP_ID  
ALGOLIA_ADMIN_KEY =  YOUR_ADMIN_KEY  
ALGOLIA_INDEX_NAME =  YOUR_INDEX_NAME  
ALGOLIA_INDEX_FILE =  PATH/TO/algolia.json  

我的配置:

[gavin@kvm-douboer ~/myweb]$ cat .env  
ALGOLIA_APP_ID = 67T0HBIEFP  
ALGOLIA_ADMIN_KEY = e712ba7148f242911a6f33da81e02a7f  
ALGOLIA_INDEX_NAME = gavin  
ALGOLIA_INDEX_FILE = public/algolia.json  

Now you can push your index to Algolia by simply running:

$ npm run algolia  

Add the following variables to your hugo site config so the search page can get access to algolia index data in the cloud:

algolia_search = true  
algolia_appId = YOUR_APP_ID  
algolia_indexName = YOUR_INDEX_NAME  
algolia_apiKey = YOUR_SEARCH_ONLY_KEY  

思路

搭建git服务,git目录作为网站的主目录,可以远程通过git命令直接发布到这个目录
用nginx来做web server

HOOK自动化部署发布

记录在这里: https://gitee.com/douboer/testhook

可以运行,问题是gitee太坑,文件量大了以后上传都是问题。 ❌已废弃,该用自搭建git server

运行

[gavin@kvm-douboer ~/myweb]$ pwd  
/home/gavin/myweb  

在服务器侧该目录下运行:

[gavin@kvm-douboer ~]$ sudo hugo server -D --bind 24.233.3.126 -p 80 --baseURL=http://biboer.cn &  

20240222


有问题,git是密文方式存储,nginx不能直接解析;
变通的办法是,用一个定时任务发布到nginx指向的目录。
client: A1(从gitserver拉下来,日常编辑维护)
⬆️
server: git server –> A2(从gitserver定时拉取,不会手动变更) <– nginx


hexo
wordpress
hugo
markdown

过程记录

20240222

yum install net-tools -y
netstat -lnpt

  • hugo example无法访问。
    hugo server -D –themesDir ../..

✅solve:
cd /home/gavin/notrack/exampleSite
hugo server -D –themesDir ../.. –bind 24.233.3.126 -p 80 –baseURL=http://24.233.3.126:80

–themesDir
themes目录所在的路径(相对于当前执行路径)

20240223

https://gohugo.io/getting-started/quick-start/


git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke  

vs. ❓

git remote add origin https://github.com/theNewDynamic/gohugo-theme-ananke.git  
git pull  

20240224

find | grep config. | xargs -I {} cp {} /tmp  

hugo server –bind 24.233.3.126 -p 80 –baseURL=http://24.233.3.126:80

20240225

部署hugo-theme-cleanwhite,穿越完成。
研究config.toml,algolia搜索没解决。

已解决。

  • 🔔 markdown不换行问题,末尾加两空格

20240225

✅Solve:

git branch -l  
git checkout master  

20240226

  • markdown头部解析及方便维护问题。

  • npm❓

  • 通过webhook,自动部署服务
    本地修改 – 提交到github/gitee – 触发webhook – push到web服务器

  • nodejs环境
    问AI,在服务器侧写一段js代码,监听80端口用户访问http://www.biboer.cn/xxx/,当用户访问该链接触发服务器侧调用shell脚本“pushshell”,并打印log
    用python代码解决。

  • ./themes/hugo-theme-cleanwhite/layouts/404.html # 定义404页

20240228

  • 从notebook采编代码,未完成❓
    • 解析markdown文件,按目录头(##)分割文件,输出到不同的文件中。
      • 文件名使用:目录标题.md
      • 生成的文件插入头部

格式:parsedairy.py -t -l 2 *.md
-t 时间解析,放到文件头的date中,如: “date: 2024-01-00 18:00:00”
-l num,解析到哪一级,如##,num为2

  • algolia 搜索,未成功❓
    ✅Solved

  • hugo命令生成静态页面public作用,发布流程❓
    A:自己部署nginx等web service,发布到相应目录部署。
    用hugo自带的服务器能力,不需要用hugo命令生成public
    ✅用nginx替换 Solved

20240310

<script>  
var _hmt = _hmt 

[];

(function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?8af1866964126ae65f4b6d38d2030b73"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script>

tracking ID: 8af1866964126ae65f4b6d38d2030b73
写到config.toml的ba_track_id中,即可。

模版中已经吧以上scipt写到themes/hugo-theme-cleanwhite/layouts/partials/footer.html中。
因此,所有页面加载时,都会附加以上脚本。

  • 图床实际上没有必要使用,用filezilla更为方便。
    本地目录直接上传目标/home/gavin/myweb/static/img即可。
    文章中直接引用name.jpg,相当高效。

  • 文章的管理也一样,filezilla扔到/home/gavin/myweb/content/post下即可。

  • 如需修改webserver中myweb下的其他文件,在本地修改完,git push上去即可。
    gitee上的webhook会触发推送到webserver上。great!!! ✅

Q & A

  • git server上以明文形式保存目录吗?
    A: 加密
  • ssh免密登录,无效❓
ssh-keygen  
ssh-copy-id ~/.ssh/id_rsa.pub -p 21174 gavin@biboer.cn  

A: PasswordAuthentication no

  • hugo命令发布到public以后,部署❓

  • 远程拉取文件,scp出错❓
    scp gavin@biboer.cn:/tmp/config* .
    A: 通配符问题,在zshrc中加配置。

echo "setopt nonomatch" >> ~/.zshrc  
source ~/.zshrc  
git rm -r --cached themes/hexo-theme-akarin  
  • [gavin@kvm-douboer ~/myweb]$ sudo npm run algolia

myweb@1.0.0 algolia /home/gavin/myweb
atomic-algolia
(node:62111) UnhandledPromiseRejectionWarning: AlgoliaSearchNetworkError: connect ECONNREFUSED 127.0.0.1:443
at ClientRequest.error (/home/gavin/myweb/node_modules/algoliasearch/src/server/builds/node.js:233:14)
at Object.onceWrapper (events.js:286:20)
at ClientRequest.emit (events.js:198:13)
at TLSSocket.socketErrorListener (_http_client.js:401:9)
at TLSSocket.emit (events.js:198:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:62111) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:62111) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[gavin@kvm-douboer ~/myweb]$ sudo npm run algolia
❗️Solve:

> cat .env  
ALGOLIA_APP_ID = 67THBIFP  
ALGOLIA_ADMIN_KEY = e712b7148f249116f33a81e02a7f  
ALGOLIA_INDEX_NAME = gavin  
ALGOLIA_INDEX_FILE = public/algolia.json  
  1. 查找docker包
    [gavin@kvm-douboer ~]$ docker search twikoo
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.  
INDEX       NAME                              DESCRIPTION             STARS       OFFICIAL    AUTOMATED  
docker.io   docker.io/imaegoo/twikoo          Twikoo 私有部署 Docker 镜像。  6  
docker.io   docker.io/llnancy/twikoo                                  0  
docker.io   docker.io/lzc256/twikoo                                   0  
docker.io   docker.io/colsrch/twikoo                                  0  
docker.io   docker.io/dijkeuorg/twikoo-arm64                          0  
  1. 拉到本地
sudo docker pull docker.io/imaegoo/twikoo  
  1. 启动服务
docker run -d -p 8081:8080 twikoo  
# docker run -p 8084:8080 -v ${PWD}/data:/app/data -d docker.io/imaegoo/twikoo  

如端口被占用,可用如下命令查看占用端口,和PID,如应用不需要,可kill该PID

netstat -lnpt  
  1. 浏览器输入:http://biboer.cn:8081,返回
     {"code":100,"message":"Twikoo 浜戝嚱鏁拌繍琛屾甯革紝璇峰弬鑰� https://twikoo.js.org/frontend.html 瀹屾垚鍓嶇鐨勯厤缃�","version":"1.6.31"}  
  1. 在config.toml中增加:
twikoo_env_id = "http://biboer.cn:8081"  

完成以上后,可以评论。但上传图片显示:"上传失败:未配置图片上传服务"

托管主机和域名申请

https://www.5678yun.com/user/domain/
域名:biboer.cn
m。。。23

http://www.idc35.com/user/register2.asp
IP:24.233.3.126
端口:21174
用户名:root/ma..23

scp -P 21174 id_rsa.pub gavin@24.233.3.126:~  

端口已修改为22

其他

  • 开源图床
  • 开源文件上传服务

参考网站