浮之静

公众号排版:创建项目

初始化

在一个自己喜欢的目录下创建一个空文件夹(我这里创建 wechat-posts,然后进入该目录),使用以下命令,你会得到一个 package.json 文件。然后创建 src/main.mjs 文件。

npm init -y

然后创建以下文件 posts/hello/index.md、posts/hello2/index.md。hello 和 hello2 自定义即可。

# 目录结构如下
wechat-posts # 根路径
├── node_modules # 安装包依赖目录,不需要关心
├── package-lock.json
├── package.json # 由 npm init 生成
├── posts # 需要写文章的目录
│ ├── hello
│ │ ├── assets # 存放资源的文件夹,比如图片
│ │ ├── index.html # 程序生成的 html
│ │ └── index.md # 我们需要写的文章
│ └── hello2
│ ├── index.html # 程序生成的 html
│ └── index.md # 我们需要写的文章
└── src # 源码目录,由我们自己创建
└── main.mjs
📌 创建项目文件夹

尽量使用英文名,不要包含特殊字符,不然可能会出现一些奇怪的问题。

  • 🔴 不推荐:@my+blog、!123*、#$abc 等

  • 🟢 推荐:my-blog、my_blog blog_123 等

生成的 package.json 内容如下:

{
"name": "wechat-posts",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}