Total Pageviews

Thursday, 27 November 2025

解决基于nextjs的静态博客程序不能嵌入图片的问题

 我看到此帖子https://brevifolia-nextjs.vercel.app/blog/bali,看到其文中嵌入了图片,我想知道作者是怎么做到的,于是查看其源帖:

https://github.com/kendallstrautman/brevifolia-nextjs/blob/master/posts/bali.md?plain=1,发现在第10行,有这么一段代码: ![bali-monkey](../static/mahkeo-monkey.jpg)

然后访问static目录:https://github.com/kendallstrautman/brevifolia-nextjs/tree/master/public/static,发现里面有mahkeo-monkey.jpg (https://github.com/kendallstrautman/brevifolia-nextjs/blob/master/public/static/mahkeo-monkey.jpg),可见可以上传图片文件到static目录:https://github.com/kendallstrautman/brevifolia-nextjs/tree/master/public/static,


 于是,如法炮制,我在https://github.com/briteming/nmbt/tree/main/public那里,上传了图片文件chicken-leg.png (https://github.com/briteming/nmbt/blob/main/public/chicken-leg.png),当然也可在public目录下,新建static目录,然后上传图片文件到public/static目录,只是没必要那么做,上传到public目录即可。

 然后访问https://github.com/briteming/nmbt/tree/main/posts,新建源帖:chicken-leg.mdx,内容为:

---
title: 诱人的鸡腿
date: "2025-11-27T16:44:00"
tags: ['misc1', 'misc2']
---

![chicken-leg](../chicken-leg.png)

这是诱人的鸡腿,尝一下吗?

2分钟后,博客里的新帖发表成功:https://nmbt.vercel.app/posts/chicken-leg,里面果然成功嵌入了图片。

关于‘扬州’那篇文章,如果要这样做,得把全部图片文件保存到本地电脑,然后上传到github.com, 工作量有点大。 

No comments:

Post a Comment