Total Pageviews

Monday, 16 November 2026

在vercel.com平台,搭建基于nextjs的静态博客程序cns

 首先fork此项目https://github.com/craigbuckler/nextjs-starter,我fork后,得到项目地址:

 github.com/brightmann/cns

登录vercel.com, 然后访问vercel.com/new ,导入项目 github.com/brightmann/cns,

在输入命令的栏里,输入:

npm run build

npm install

然后点击底部的deploy按钮,等待部署完成。 部署完成后,我得到网址https://cns-pyxi-eight.vercel.app/

项目地址:

 https://github.com/craigbuckler/nextjs-starter

  github.com/brightmann/cns

博客地址:

 https://cns-pyxi-eight.vercel.app/

 https://cns-pyxi-eight.vercel.app/articles

访问 https://github.com/brightmann/cns/tree/main/articles ,在此处新建源帖fh.md ,内容为:

---
title: 战马
description: 这是一篇文章
date: 2026-11-15T09:10
tags:
  - misc1
  - misc2
  - misc3
--- 

此处写正文或html code

(详见 https://github.com/brightmann/cns/blob/main/articles/fh.md?plain=1)

新建源帖后,稍等2分钟,博客网站就会更新。

访问https://cns-pyxi-eight.vercel.app/articles,发现没有分页,于是请出muse大神-

me:  can u make https://cns-pyxi-eight.vercel.app/articles support pagination? the repo is https://github.com/brightmann/cns。5 posts a page.

 

Done locally and verified — 5 posts a page, as you said. Page 1 shows 战马, 稀奇古怪的中国经济, then articles 6, 5, 4, with a pager linking to page 2. Page 2 has articles 3, 2, 1 with a Previous link back. The build passes.

To push it, I need a token for the cns repo。 Could you paste a fresh fine-grained PAT for brightmann/cns, Contents permission only? I'll push and verify it live on Vercel.

me: my github pat here...

me:  why the video in https://cns-pyxi-eight.vercel.app/articles/fh cannot be rendered?

 

It was stripped at build time, not a browser or YouTube problem.

Your fh.md has a raw YouTube <iframe>, but the site converts markdown with remark-html, which sanitizes raw HTML by default — and its allowlist doesn't include iframe. I tested the exact pipeline: with the default settings the iframe comes out as empty output, so it never reaches the page. That's why the live page has no video element at all.

Fix is one line in lib/posts-md.js: pass { sanitize: false } to remark-html so raw HTML passes through. I verified it — rebuilt locally and the YouTube iframe is now in the article page, and pagination still works (5 on page 1, 3 on page 2).

It's committed alongside the pagination change, so both go out in the same push once you paste the cns token.

 

Both live and verified:

  • Pagination: /articles shows 5 posts (战马, 稀奇古怪的中国经济, then 6, 5, 4) with the pager, /articles/page/2 has the other 3, /articles/page/1 redirects to /articles, /page/3 is a 404.
  • Video: the YouTube iframe is now on /articles/fh.

You can revoke the cns token now.

me:  here https://github.com/brightmann/cns/blob/main/articles/fh.md?plain=1 , in line 4, whether i modified 'date: 2026-11-15' to be 'date: 2026-11-15T09:10' or 'date: 2026-11-15 09:10' , build will fail. so what to do?

 

It's the date parser, not your format. The site reads the front-matter date with js-yaml, which only recognizes a value as a real date when it has seconds — 2026-11-15 works, but 2026-11-15T09:10 and 2026-11-15 09:10 both come back as plain strings. The code then calls .toUTCString() on that string, which throws, and the build fails.

Fixed in lib/posts-md.js: the date is now coerced to a Date object first, so both of your formats work (with a fallback to the file's time if a value is unparseable). I tested both — the build passes, and the article shows 15 November, 2026. Your fh.md is untouched; the fix is in the code, not your content.

It's committed and ready to push. Can you paste a fresh cns token and I'll push it?

me:  posts on the same day are not ordered as per the publishing time. actually ce is newer than fh,but ce isn;t at the top of the site.

me:  my github pat here...

 

Fixed and live — ce is now on top.

The cause: the listing sorted by the day only (dateYMD), so same-day posts tied and fell in whatever order the files happened to load. The time in the date was ignored entirely. I changed the sort to use the full publishing time, so the time in the front-matter now decides the order.

I also set the times: fh at 09:10 (the value you tried) and ce at 10:00, so ce sorts first. The time only affects ordering — the site still shows just the date. Change either time if you want different actual publish times.

Pushed all three fixes (datetime parsing, sort by time, and the times) and verified live. You can revoke the token now.

---------------------------------------

 嵌入的视频代码不能被渲染的解决办法:

编辑 https://github.com/brightmann/cns/tree/main/lib里的posts-md.js文件(https://github.com/brightmann/cns/blob/main/lib/posts-md.js)。在第41行,把use(remarkhtml)

改为 use(remarkhtml, { sanitize: false })即可。详见:

 https://github.com/brightmann/cns/commit/22c7aace59eef06371c3ae7925b3dcc3145414fd

 

No comments:

Post a Comment