My new JamStack-based blog

This article was last updated on: February 7, 2024 pm

overview

On a whim today, I’ll introduce my new blog site – https://e-whisper.com

I am doing basic platform PaaS operation and maintenance and architecture, I like to write down and take notes about the new knowledge I learned at work, and suddenly one day I hold the concept of “resource sharing, the world is public”, share my learning experience, and also make my articles more standardized.

I started tossing and turning my blog in 2019, and then in 2021 I made a new version of my blog, and in the latest version of the blog, both used and deployed, it used JamStack’s technical architecture and tools. So far, the effect is also good.

🧠Issue:

What exactly is the Jamstack of the current fire in the “translation”? 》

My first generation of bloggers

The first generation of websites, which are still left here - https://www.e-whisper.com composed Pelican static site generator,NGINX Web Server,DockerTencent Cloud Cloud host provides support. The theme is currently fromSmashing Magazine

The effect is shown in the following figure:

my-pelican-blog-screenshot

📚Resources:

Pelican is a static site generator written in Python. Highlights include:

  • Write content directly in reStructuredText or Markdown format editors
  • Contains a simple CLI tool to (re)build your site
  • Easy to interface with distributed version control systems and web hooks
  • Fully static output is easy to host anywhere

Second generation - JamStack-based blog

Second Generation Website —— https://e-whisper.com composed Hexo static site generator,Qiniu Cloud - Object storage and CDN Provide image storage and URL,Tencent Cloud CloudBase - Static website hosting Provide static website hosting support,valine or Twikoo Provide comment system technical support, blog visits and comment information storage LeanCloud or Tencent Cloud CloudBase - User Management, statistical analysis passedBaidu statistics and LeanCloud To achieve, the blog homepage dynamic poetry display byIn a word, the Developer CenterInterface provided. The theme is currently from hexo-theme-fluid

The effect is shown in the following figure:

my-fluid-show

Let’s introduce them one by one.

JAM

What is JamStack?

📚Resources:

JAM in Jamstack architecture refers to client-side JavaScript, reusable back-end APIs, and user interface markup, such as HTML and CSS.
The key feature of Jamstack is a clear distinction between front-end web UI and API-based back-end services. Unlike vertically integrated traditional web applications, Jamstack applications are modular and decentralized: the UI can be distributed through static web servers, CDNs, and even blockchain-based storage; Backend API services can be deployed on the cloud or served by edge nodes nearby.

Let’s start with the JAM architecture

JAM - Technical architecture for my blog

J - JavaScript

J stands for client-side JavaScript, so the main JavaScript involved in my blog is as follows:

  • JS static site generator framework: Hexo, I wrote articles in Markdown format on my computer, passed hexo g Generate static pages of the website and pass them hexo deploy Deploy.

  • Deploy hostingTencent Cloud CloudBase, here is where it is used:

    • CloudBase CLI: Used for and hexo deploy Work together to publish website files to Tencent Cloud (static parts are specifically used: DNSPod, COS and CDN)
    • In addition to the JavaScript part, there are also sections that cover APIs (more on this later):
      • User management
      • database
      • SCF
  • Static website comment systemTwikoo, here it uses its JS front-end and Tencent Cloud CloudBase-based SCF background.

  • Web page visit statistics

    • Baidu statistics: Used to do webmaster web visit statistics and analysis.
    • LeanCloud: For PV UV display. Its “data storage” service is mainly used here.

Baidu’s statistical effect is as follows:

百度统计

The LeanCloud display effect is as follows:

首页 PV UV 展示

文章浏览量展示

The back-end storage data looks like this:

LeanCloud 后台数据存储

📚Resources:

  • Hexo is a fast, concise, and efficient blogging framework. Hexo uses Markdown(or other rendering engines) parse the article and in seconds, generate static web pages with beautiful themes. Hexo is based on JavaScript and Node .js.

  • Tencent Cloud CloudBase: Cloud Development (Tencent CloudBase, TCB) is a cloud-native integrated development environment and tool platform provided by Tencent Cloud, which provides developers with high-availability and automatically elastically scaled back-end cloud services, including serverless capabilities such as computing, storage, and hosting, which can be used to develop multiple terminal applications (mini programs, official accounts, web applications, Flutter clients, etc.) in the cloud. It helps developers build and manage back-end services and cloud resources in a unified manner, avoiding cumbersome server construction and O&M in the application development process, allowing developers to focus on the implementation of business logic, with lower development thresholds and higher efficiency.

    • CloudBase CLI is an open source command-line interface interactive tool for cloud development (Tencent CloudBase (TCB), based on JavaScript and Node .js, used to help users quickly and conveniently deploy projects and manage cloud development resources.
  • Twikoo: A concise, secure and free static website review system, based on Tencent Cloud development. Some of the features are as follows:

    • Support reply, like
    • No additional adaptation is required, and it can be used with light theme and dark theme
    • API calls are supported to obtain the number of article comments and the latest comments in batches
    • When visitors enter the QQ number in the nickname column, the QQ nickname and QQ email address will be automatically completed
    • Visitors fill in the digital QQ email address, and will use the QQ avatar as the comment avatar
    • Support pasting pictures in the comment box (can be disabled)
    • Support for inserting pictures (can be disabled)
    • Support for inserting emoticons (can be disabled)
    • Support Ctrl + Enter quick replies
    • The comment box content saves the draft in real time, and the refresh is not lost
    • Supports code highlighting by language
    • Privacy information security (sensitive fields (email, IP, environment configuration, etc.) are not leaked through SCF)
    • Support for human review mode
    • Prevents XSS injection
    • Support for limiting the maximum number of comments per IP per 10 minutes
    • Support for custom emoticon lists
    • Embedded admin panel, login with password, easy to view comments, hide comments, delete comments, modify configurations
    • Support for importing comments from Valine, Artalk, Disqus

    The effect is as follows:

    Twikoo 夜间模式

  • LeanCloud: The services provided by LeanCloud are essentially the same as Tencent Cloud’s CloudBase. LeanCloud’s leading serverless cloud service provides strong back-end support for product development. Provide one-stop back-end services, such as data storage, cloud engine, instant messaging, etc.

A - API

A refers to reusable backend APIs. In fact, J and A are closely coordinated, and we can see in the previous paragraph that many JavaScripts eventually call APIs to add, delete, modify, and check data. The main APIs covered in my blog are:

Static website comment API

If you visit my website –Best Practices for Production on Containerized Application Systems - Dongfeng Weiming Technology Blog (e-whisper.com), look at the comments, open the browser’s F12, you can see that the API of the actual Twikoo POST is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
curl 'https://ewhisper-5g565139594f9b52.ap-shanghai.tcb-api.tencentcloudapi.com/web?env=ewhisper-5g565139594f9b52' \
-H 'authority: ewhisper-5g565139594f9b52.ap-shanghai.tcb-api.tencentcloudapi.com' \
-H 'sec-ch-ua: "Microsoft Edge";v="95", "Chromium";v="95", ";Not A Brand";v="99"' \
-H 'x-tcb-region: ap-shanghai' \
-H 'x-sdk-version: @cloudbase/js-sdk/1.7.0' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.38' \
-H 'content-type: application/json;charset=UTF-8' \
-H 'x-seqid: 04c3430d22965' \
-H 'x-tcb-trace: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1dWlkIjoiZWQ1OWE2MmFiYmIyNDZkY2JiNTRiODVjMzU5MGMxNTEiLCJsYXN0UmVwb3J0VGltZSI6MTYzNTY0NzI4MTI2OSwiaWF0IjoxNjM1NjQ3MjgxfQ.GiVnirzhrEf7AnNxV_QejyH9Tk7shmmVG6Xh5yiUPn0' \
-H 'sec-ch-ua-platform: "Windows"' \
-H 'accept: */*' \
-H 'origin: https://e-whisper.com' \
-H 'sec-fetch-site: cross-site' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-dest: empty' \
-H 'referer: https://e-whisper.com/' \
-H 'accept-language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7' \
--data-raw '{"action":"functions.invokeFunction","dataVersion":"2020-01-10","env":"ewhisper-5g565139594f9b52","function_name":"twikoo","request_data":"{\"event\":\"COMMENT_GET\",\"url\":\"/posts/14417/\"}","access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoie1wibG9naW5UeXBlXCI6XCJBTk9OWU1PVVNcIixcImVudk5hbWVcIjpcImV3aGlzcGVyLTVnNTY1MTM5NTk0ZjliNTJcIixcInV1aWRcIjpcImVkNTlhNjJhYmJiMjQ2ZGNiYjU0Yjg1YzM1OTBjMTUxXCJ9IiwiaWF0IjoxNjM1NjUwOTU4LCJleHAiOjE2MzU2NTQ1NTh9.8hDap2wwrTII2Ine8F9jjDzCGUKW_e80pb4KvpGM64U;1635566422","seqId":"04c3430d22965"}' \
--compressed

The response returned by the API is:

1
2
3
4
5
6
{
"requestId": "91765a8a-39fc-11ec-9ab1-b2a89f885dbc",
"data": {
"response_data": "{\"data\":[{\"id\":\"cd045e75610b657002fe22fb26922cc4\",\"nick\":\" 凯西 Casey\",\"avatar\":\"https://thirdqq.qlogo.cn/g?b=sdk&k=JtvoGTkW8mBlnXNSFnxcxg&s=140&t=1557419902\",\"mailMd5\":\"097b6659c25b25c1ad2d792c6d5a953e\",\"link\":\"\",\"comment\":\"<p> 自动关联 qq 头像 <img alt=\\\":bilibiliHotKey-20:\\\" src=\\\"https://twikoo-magic.oss-cn-hangzhou.aliyuncs.com/bilibiliHotKey/20.jpg\\\" class=\\\"tk-owo-emotion\\\"> </p>\\n\",\"os\":\"Android 11\",\"browser\":\"Miui 15.1.12\",\"master\":false,\"like\":0,\"liked\":false,\"replies\":[],\"ruser\":null,\"isSpam\":false,\"created\":1628136816139,\"updated\":1628136816139},{\"id\":\"cd045e75610b634002fc99751dbc207c\",\"nick\":\" 小囧 \",\"mailMd5\":\"27add2425f31777763528269b4060ec1\",\"link\":\"\",\"comment\":\"<p><img alt=\\\":bilibiliHotKey-24:\\\" src=\\\"https://twikoo-magic.oss-cn-hangzhou.aliyuncs.com/bilibiliHotKey/24.jpg\\\" class=\\\"tk-owo-emotion\\\"> </p>\\n\",\"os\":\"Android 11\",\"browser\":\"Miui 15.1.12\",\"master\":false,\"like\":1,\"liked\":false,\"replies\":[],\"ruser\":null,\"isSpam\":false,\"created\":1628136256345,\"updated\":1628136256345},{\"id\":\"610b366fcb9d18021c807485\",\"nick\":\" 东风微鸣 \",\"mailMd5\":\"7c743bc6ac83171e35a5aa8bd66cc1ea\",\"link\":\"https://e-whisper.com\",\"comment\":\"<p>&lt;img class=&quot;vemoji&quot; src=&quot;https://cdn.jsdelivr.net/gh/walinejs/[email protected]/alus/alus_blush.png&quot; alt=&quot;alus_blush&quot;&gt;&lt;img class=&quot;vemoji&quot; src=&quot;https://cdn.jsdelivr.net/gh/walinejs/[email protected]/bilibili/bb_sunglasses.png&quot; alt=&quot;bb_sunglasses&quot;&gt;&lt;img class=&quot;vemoji&quot; src=&quot;https://cdn.jsdelivr.net/gh/walinejs/[email protected]/qq/qq_confounded.gif&quot; alt=&quot;qq_confounded&quot;&gt;&lt;img class=&quot;vemoji&quot; src=&quot;https://cdn.jsdelivr.net/gh/walinejs/[email protected]/tieba/tieba_antic.png&quot; alt=&quot;tieba_antic&quot;&gt;&lt;img class=&quot;vemoji&quot; src=&quot;https://cdn.jsdelivr.net/gh/walinejs/[email protected]/tw-emoji/1f47d.png&quot; alt=&quot;1f47d&quot;&gt;&lt;img class=&quot;vemoji&quot; src=&quot;https://cdn.jsdelivr.net/gh/walinejs/[email protected]/weibo/weibo_cat_cry.png&quot; alt=&quot;weibo_cat_cry&quot;&gt;</p>\\n\",\"os\":\"Windows 10\",\"browser\":\"Microsoft Edge 92.0.902.62\",\"master\":false,\"like\":0,\"liked\":false,\"replies\":[],\"ruser\":null,\"created\":1628124783184,\"updated\":1628124783184}],\"more\":false,\"count\":3}"
}
}

The actual content is:

comment

Web page access statistics API

Baidu statistics are too complicated, I don’t understand much, the URL is:https://hm.baidu.com/hm.js Readers can see for themselves.

The LeanCloud APIs for counting PV, UV, and specific article views are:

PV:

https://lrbbjugq.lc-cn-e1-shared.com/1.1/classes/Counter?where={"target"%3A"site-pv"}

The response reads:

1
2
3
4
5
6
7
8
9
10
11
{
"results": [
{
"target": "site-pv",
"time": 1395,
"createdAt": "2021-07-10T07:40:59.569Z",
"updatedAt": "2021-10-31T03:30:15.933Z",
"objectId": "60e94f0b55ba67136bafb203"
}
]
}

UV:

https://lrbbjugq.lc-cn-e1-shared.com/1.1/classes/Counter?where={"target"%3A"site-uv"}

The response reads:

1
2
3
4
5
6
7
8
9
10
11
{
"results": [
{
"target": "site-uv",
"time": 397,
"createdAt": "2021-07-10T07:40:54.146Z",
"updatedAt": "2021-10-31T02:15:31.349Z",
"objectId": "60e94f06d3c62b4544b9ff5d"
}
]
}

Specific article reads: toBest Practices for Production on Containerized Application Systems - Dongfeng Weiming Technology Blog (e-whisper.com)for example

https://lrbbjugq.lc-cn-e1-shared.com/1.1/classes/Counter?where={"target"%3A"%2Fposts%2F14417%2F"}

The response reads:

1
2
3
4
5
6
7
8
9
10
11
{
"results": [
{
"target": "/posts/14417/",
"time": 28,
"createdAt": "2021-07-31T08:39:50.194Z",
"updatedAt": "2021-10-31T03:30:15.926Z",
"objectId": "61050c5697a09641df17407d"
}
]
}
Home Slogan

If you enter my homepage and refresh it a few times, you will find that different ancient verses will appear on the Slogan on the homepage. As follows:

博客首页古诗句 Slogan

This is actually the API called, and the dynamic poetry display on the homepage of the blog is made byIn a word, the Developer CenterInterface provided.

📚Resources:

Yiyan is a project created in 2016 and originally used for personal purposes. At present, it has been transformed into a public welfare project, operated by the Mengchuang team to provide services for everyone. The so-called 一言 (ヒトコト), that is, a sentence. This sentence can convey moving, can be a smile, can be thought-provoking. In short, a word represents the touch of words, the communication of souls.

The specific call URL is:https://v1.hitokoto.cn/?c=ic=i Indicates that the sentence type © is poetry (i).

The response returned is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"id": 5545,
"uuid": "5d9def79-c283-4c4c-a9cb-f44ac8da26da",
"hitokoto": " 采得百花成蜜后,为谁辛苦为谁甜。",
"type": "i",
"from": " 蜂 ",
"from_who": " 罗隐 ",
"creator": "a632079",
"creator_uid": 1044,
"reviewer": 1044,
"commit_from": "api",
"created_at": "1586266392",
"length": 16
}

M - Markup

M refers to the markup of user interfaces, such as HTML and CSS.

My blog compared several popular Hexo themes and finally chosen fluid 。 Here are the themes I’ve used and my brief reviews.

  • NexT: Most used by people, updated frequently, Chinese, no Chinese documentation
  • icarus: The theme is to my taste, updated frequently, no Chinese documentation
  • matery: Fancy, Chinese fully supported
  • fluid: Concise, full Chinese
  • butterfly:Chinese Traditional

📚Resources:

Fluid is a Material Design-style theme based on Hexo, with a minimalist design that helps you focus on writing, by Fluid-devResponsible for development and maintenance.
Topic GitHub: https://github.com/fluid-dev/hexo-theme-fluid
Preview a site:Fluid’s blogzkqiang’s blog
You can browse it Hello Fluid - Hexo Theme Fluid (fluid-dev.com) to experience the style of the theme

JAM - My Blog Writing Publishing Process

First, articles are all hosted on Git. Install the dependencies on my computer: Git, Node.js, VSCode (used as Markdown format article writing, terminal terminal, and Git version management),hexo-cli(Hexo’s command line),hexo-theme-fluid(fluid theme) and @cloudbase/cli(Tencent Cloud CloudBase CLI).

Second, execute it in the terminal hexo new " 新文章 " Create a new markdown file and write and edit it with VSCode.

After the article is completed, it is executed through the terminal hexo s Generate a new article page and preview it locally.

Finally, pass cloudbase framework deploy ... Publish to Tencent Cloud.

I’ll talk about it in detail here cloudbase framework deploy ... What have been done, as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
CloudBase CLI 1.9.2
CloudBase Framework 1.8.16
______ __ __ ____
/ ____// /____ __ __ ____/ // __ ) ____ _ _____ ___
/ / / // __ \ / / / // __ // __ |/ __ `// ___// _ \
/ /___ / // /_/ // /_/ // /_/ // /_/ // /_/ /(__)/ __/
\____//_/_\____/ \__,_/ \__,_//_____/ \__,_//____/ \___/ __
/ ____/_____ ____ _ ____ ___ ___ _ __ ____ _____ / /__
/ /_ / ___// __ `// __ `__ \ / _ \| | /| / // __ \ / ___// //_/
/ __/ / / / /_/ // / / / / // __/| |/ |/ // /_/ // / / ,<
/_/ /_/ \__,_//_/ /_/ /_/ \___/ |__/|__/ \____//_/ /_/|_|

CloudBase Framework info EnvId ewhisper-xxxxx # 作者备注:CloudBase 的环境 ID
CloudBase Framework info Region ap-shanghai # 作者备注:腾讯云区域
CloudBase Framework info Validate config file success.
CloudBase Framework info AppName ewhisper
CloudBase Framework info 📦 install plugins
CloudBase Framework info callHooks 'preDeploy' # 作者备注:部署前操作
CloudBase Framework info 🔧 init: hexo... # 作者备注:init
CloudBase Framework info Website 插件会自动开启静态网页托管能力,需要当前环境为 [按量计费] 模式 # 作者备注:环境是按量计费的。
CloudBase Framework info Website 插件会部署应用资源到当前静态托管的 / 目录下
CloudBase Framework info 🔨 build: hexo... # 作者备注:build,就是调用 `npx hexo generate`
CloudBase Framework info running 'npm install --prefer-offline --no-audit --progress=false'
...
CloudBase Framework info running 'npx hexo generate'
# 作者备注:以下是 Hexo Generate 日志
INFO Validating config
INFO Start processing
INFO [Fluid] 读取 _config.yml 中 theme_config 配置项覆盖配置
INFO Generate link [41870] for post [source/_posts/ 我的基于 JamStack 的新博客.md][我的基于 JamStack 的新博客]
INFO Generated: categories [['CloudComputing' ]] for post [source/_posts/ 我的基于 JamStack 的新博客.md][我的基于 JamStack 的新博客]
...
INFO 292 files generated in 1.8 s
# 作者备注:以上是 Hexo Generate 日志
CloudBase Framework info 🧬 compile: hexo... # 作者备注:静态网站没有编译过程
CloudBase Framework info callHooks 'postCompile'
正在部署 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 100% 40.0 s
正在部署[░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 100% 45.1 s
CloudBase Framework info 🚀 deploy: hexo... # 作者备注:部署到腾讯云,其实调用的就是腾讯云 COS 的上传 API
CloudBase Framework info 🚀 网站部署成功
CloudBase Framework info callHooks 'postDeploy' # 作者备注:部署后展示应用信息
CloudBase Framework info 🌐 应用入口信息:
🔗 网站入口: https://ewhisper-xxx.tcloudbaseapp.com/
CloudBase Framework info ✨ done

In the meantime, version management and synchronization of articles are also carried out through Git.

JAM - Deployment architecture for my blog

The common user access routes for JAM are as follows:

JAM

Static site section

The site produced by Hexo is a completely static site, all static files, including: HTML, CSS, JavaScript, and images. These static files, through cloudbase framework deploy ... , publish toTencent Cloud CloudBase - Static website hosting。 In fact, static files are published to 2 Tencent Cloud products:

  1. Tencent Cloud Object Storage COS: Static files are stored in COS as objects.
  2. Tencent Cloud CDN: Static files in COS are cached in Tencent Cloud’s CDN.

When a user browses the site, the process is as follows:

  1. Visit:https://e-whisper.com;
  2. <e-whisper.com> domain name resolves to CName:<e-whisper.com.cdn.dnsv1.com> in DNS; Go to Tencent Cloud CDN
  3. If the CDN hits, return directly; If the CDN does not hit, it will return to the address of Tencent Cloud COS to access the source file.

API section

For the API part, the following components need to be provisioned, installed and deployed:

  • Static website comment system:Twikoo, see for deployment methods Twikoo is quick to get started
  • Web page access statistics API:LeanCloud。 LeanCloud only needs to apply for an account and get the corresponding domain name and AKSK.

summary

That’s it for my JamStack-based blog — https://e-whisper.com。 Mainly based on: Hexo, Fluid theme, Twikoo review system, LeanCloud, and Tencent Cloud CloudBase.

From my perspective, some of the main differences between JamStack and traditional LNMP development include:

  • Jamstack does not require installing or managing an operating system (such as Linux)
  • Jamstack does not require administrative security policies (server firewalls)
  • Jamstack does not require installing or managing application databases such as MySQL
  • Jamstack can deploy a web site or web app without using an HTTP (web) server, such as Apache

Overall, there are 4 main benefits of choosing to use Jamstack to create a website: Cost effectiveness, performance improvements, better security, and a better user/developer experience

Welcome to experience! ✨✨✨