Use lune for scripts, migrate to bun

This commit is contained in:
Erica Marigold 2024-07-06 13:47:49 +05:30
parent aef8856c1b
commit dcfc0c9683
No known key found for this signature in database
GPG key ID: 2768CC0C23D245D1
11 changed files with 75 additions and 10469 deletions

10
.luaurc Normal file
View file

@ -0,0 +1,10 @@
{
"languageMode": "strict",
"lintErrors": true,
"lint": {
"*": true
},
"aliases": {
"pkg": "./node_modules/.luau-aliases"
}
}

50
.lune/new-post.luau Normal file
View file

@ -0,0 +1,50 @@
--> This is a script to create a new post markdown file with front-matter
local fs = require("@lune/fs")
local stdio = require("@lune/stdio")
local process = require("@lune/process")
local datetime = require("@lune/datetime")
local LuauPath = require("@pkg/luau-path")
type Path = LuauPath.Path
local Path = LuauPath.Path
local TARGET_DIR = Path.new("./src/content/posts/")
local FRONTMATTER_CONTENT = [[---
title: ${fileName}
published: ${date}
description: ''
image: ''
tags: []
category: ''
draft: false
---
]]
local function main(args: { string }): number?
local fileName = args[1]
if not fileName then
fileName = stdio.prompt("text", "Enter post name:")
end
local filePath = Path.new(fileName)
if not filePath:extension() then
filePath:setExtension("md")
end
local fullPath: Path = Path.join(TARGET_DIR, filePath)
if fs.isFile(fullPath:toString()) then
stdio.ewrite(`Error: File {fullPath} already exists!\n`)
return 1
end
local editedContents = FRONTMATTER_CONTENT:gsub("${fileName}", fileName)
:gsub("${date}", datetime.now():formatUniversalTime("%Y-%m-%dT%H:%M:%S"))
fs.writeFile(fullPath:toString(), editedContents)
print(`Post {fullPath} created!`)
return 0
end
return process.exit(main(process.args))

View file

@ -1,6 +1,8 @@
{ {
"recommendations": [ "recommendations": [
"biomejs.biome", "biomejs.biome",
"JohnnyMorganz.stylua",
"JohnnyMorganz.luau-lsp",
"astro-build.astro-vscode", "astro-build.astro-vscode",
"svelte.svelte-vscode", "svelte.svelte-vscode",
"davidanson.markdownlint" "davidanson.markdownlint"

10
.vscode/settings.json vendored
View file

@ -1,4 +1,9 @@
{ {
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@lune/": "~/.lune/.typedefs/0.8.6/",
"@pkg": "node_modules/.luau-aliases"
},
"editor.formatOnSave": true, "editor.formatOnSave": true,
"editor.defaultFormatter": "biomejs.biome", "editor.defaultFormatter": "biomejs.biome",
"[javascript]": { "[javascript]": {
@ -16,9 +21,12 @@
"[svelte]": { "[svelte]": {
"editor.defaultFormatter": "biomejs.biome", "editor.defaultFormatter": "biomejs.biome",
}, },
"[luau]": {
"editor.defaultFormatter": "JohnnyMorganz.stylua"
},
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"quickfix.biome": "always", "quickfix.biome": "always",
"source.organizeImports.biome": "always" "source.organizeImports.biome": "always"
}, },
"frontMatter.dashboard.openOnStart": false "frontMatter.dashboard.openOnStart": false,
} }

View file

@ -1,55 +0,0 @@
# 🍥Fuwari
[Astro](https://astro.build)で構築された静的ブログテンプレート
[**🖥️ライブデモ (Vercel)**](https://fuwari.vercel.app)   /   [**🌏中文**](https://github.com/saicaca/fuwari/blob/main/README.zh-CN.md)   /   [**🌏日本語**](https://github.com/saicaca/fuwari/blob/main/README.ja-JP.md)   /   [**📦旧Hexoバージョン**](https://github.com/saicaca/hexo-theme-vivia)
![Preview Image](https://raw.githubusercontent.com/saicaca/resource/main/fuwari/home.png)
## ✨ 特徴
- [x] [Astro](https://astro.build)及び [Tailwind CSS](https://tailwindcss.com)で構築
- [x] スムーズなアニメーションとページ遷移
- [x] ライト/ダークテーマ対応
- [x] カスタマイズ可能なテーマカラーとバナー
- [x] レスポンシブデザイン
- [ ] コメント機能
- [x] 検索機能
- [ ] 目次
## 🚀 使用方法
1. [テンプレート](https://github.com/saicaca/fuwari/generate)から新しいリポジトリを作成するかCloneをします。
2. ブログをローカルで編集するには、リポジトリをクローンした後、`pnpm install` と `pnpm add sharp` を実行して依存関係をインストールします。
- [pnpm](https://pnpm.io)がインストールされていない場合は `npm install -g pnpm` で導入可能です。
3. `src/config.ts`ファイルを編集する事でブログを自分好みにカスタマイズ出来ます。
4. `pnpm new-post <filename>`で新しい記事を作成し、`src/content/posts/`.フォルダ内で編集します。
5. 作成したブログをVercel、Netlify、GitHub Pagesなどにデプロイするには[ガイド](https://docs.astro.build/ja/guides/deploy/)に従って下さい。加えて、別途デプロイを行う前に`astro.config.mjs`を編集してサイト構成を変更する必要があります。
## ⚙️ 記事のフロントマター
```yaml
---
title: My First Blog Post
published: 2023-09-09
description: This is the first post of my new Astro blog.
image: /images/cover.jpg
tags: [Foo, Bar]
category: Front-end
draft: false
---
```
## 🧞 コマンド
すべてのコマンドは、ターミナルでプロジェクトのルートから実行する必要があります:
| Command | Action |
|:------------------------------------|:-------------------------------------------------|
| `pnpm install` AND `pnpm add sharp` | 依存関係のインストール |
| `pnpm dev` | `localhost:4321`で開発用ローカルサーバーを起動 |
| `pnpm build` | `./dist/`にビルド内容を出力 |
| `pnpm preview` | デプロイ前の内容をローカルでプレビュー |
| `pnpm new-post <filename>` | 新しい投稿を作成 |
| `pnpm astro ...` | `astro add`, `astro check`の様なコマンドを実行する際に使用 |
| `pnpm astro --help` | Astro CLIのヘルプを表示 |

View file

@ -1,55 +0,0 @@
# 🍥Fuwari
A static blog template built with [Astro](https://astro.build).
[**🖥Live Demo (Vercel)**](https://fuwari.vercel.app)&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;[**🌏中文 README**](https://github.com/saicaca/fuwari/blob/main/README.zh-CN.md)&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;[**🌏日本語 README**](https://github.com/saicaca/fuwari/blob/main/README.ja-JP.md)&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;[**📦Old Hexo Version**](https://github.com/saicaca/hexo-theme-vivia)
![Preview Image](https://raw.githubusercontent.com/saicaca/resource/main/fuwari/home.png)
## ✨ Features
- [x] Built with [Astro](https://astro.build) and [Tailwind CSS](https://tailwindcss.com)
- [x] Smooth animations and page transitions
- [x] Light / dark mode
- [x] Customizable theme colors & banner
- [x] Responsive design
- [ ] Comments
- [x] Search
- [ ] TOC
## 🚀 How to Use
1. [Generate a new repository](https://github.com/saicaca/fuwari/generate) from this template or fork this repository.
2. To edit your blog locally, clone your repository, run `pnpm install` AND `pnpm add sharp` to install dependencies.
- Install [pnpm](https://pnpm.io) `npm install -g pnpm` if you haven't.
3. Edit the config file `src/config.ts` to customize your blog.
4. Run `pnpm new-post <filename>` to create a new post and edit it in `src/content/posts/`.
5. Deploy your blog to Vercel, Netlify, GitHub Pages, etc. following [the guides](https://docs.astro.build/en/guides/deploy/). You need to edit the site configuration in `astro.config.mjs` before deployment.
## ⚙️ Frontmatter of Posts
```yaml
---
title: My First Blog Post
published: 2023-09-09
description: This is the first post of my new Astro blog.
image: /images/cover.jpg
tags: [Foo, Bar]
category: Front-end
draft: false
---
```
## 🧞 Commands
All commands are run from the root of the project, from a terminal:
| Command | Action |
|:------------------------------------|:-------------------------------------------------|
| `pnpm install` AND `pnpm add sharp` | Installs dependencies |
| `pnpm dev` | Starts local dev server at `localhost:4321` |
| `pnpm build` | Build your production site to `./dist/` |
| `pnpm preview` | Preview your build locally, before deploying |
| `pnpm new-post <filename>` | Create a new post |
| `pnpm astro ...` | Run CLI commands like `astro add`, `astro check` |
| `pnpm astro --help` | Get help using the Astro CLI |

View file

@ -1,55 +0,0 @@
# 🍥Fuwari
基于 [Astro](https://astro.build) 开发的静态博客模板。
[**🖥在线预览Vercel**](https://fuwari.vercel.app)&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;[**🌏English README**](https://github.com/saicaca/fuwari)&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;[**🌏日本語 README**](https://github.com/saicaca/fuwari/blob/main/README.ja-JP.md)&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;[**📦旧 Hexo 版本**](https://github.com/saicaca/hexo-theme-vivia)
![Preview Image](https://raw.githubusercontent.com/saicaca/resource/main/fuwari/home.png)
## ✨ 功能特性
- [x] 基于 Astro 和 Tailwind CSS 开发
- [x] 流畅的动画和页面过渡
- [x] 亮色 / 暗色模式
- [x] 自定义主题色和横幅图片
- [x] 响应式设计
- [ ] 评论
- [x] 搜索
- [ ] 文内目录
## 🚀 使用方法
1. 使用此模板[生成新仓库](https://github.com/saicaca/fuwari/generate)或 Fork 此仓库
2. 进行本地开发Clone 新的仓库,执行 `pnpm install``pnpm add sharp` 以安装依赖
- 若未安装 [pnpm](https://pnpm.io),执行 `npm install -g pnpm`
3. 通过配置文件 `src/config.ts` 自定义博客
4. 执行 `pnpm new-post <filename>` 创建新文章,并在 `src/content/posts/` 目录中编辑
5. 参考[官方指南](https://docs.astro.build/zh-cn/guides/deploy/)将博客部署至 Vercel, Netlify, GitHub Pages 等;部署前需编辑 `astro.config.mjs` 中的站点设置。
## ⚙️ 文章 Frontmatter
```yaml
---
title: My First Blog Post
published: 2023-09-09
description: This is the first post of my new Astro blog.
image: /images/cover.jpg
tags: [Foo, Bar]
category: Front-end
draft: false
---
```
## 🧞 指令
下列指令均需要在项目根目录执行:
| Command | Action |
|:----------------------------------|:----------------------------------|
| `pnpm install``pnpm add sharp` | 安装依赖 |
| `pnpm dev` | 在 `localhost:4321` 启动本地开发服务器 |
| `pnpm build` | 构建网站至 `./dist/` |
| `pnpm preview` | 本地预览已构建的网站 |
| `pnpm new-post <filename>` | 创建新文章 |
| `pnpm astro ...` | 执行 `astro add`, `astro check` 等指令 |
| `pnpm astro --help` | 显示 Astro CLI 帮助 |

BIN
bun.lockb Executable file

Binary file not shown.

View file

@ -3,12 +3,13 @@
"type": "module", "type": "module",
"version": "0.0.1", "version": "0.0.1",
"scripts": { "scripts": {
"prepare": "npmluau",
"dev": "astro dev", "dev": "astro dev",
"start": "astro dev", "start": "astro dev",
"build": "astro build && pagefind --site dist", "build": "astro build && pagefind --site dist",
"preview": "astro preview", "preview": "astro preview",
"astro": "astro", "astro": "astro",
"new-post": "node scripts/new-post.js", "new-post": "lune run new-post",
"fmt": "biome format --write ./src", "fmt": "biome format --write ./src",
"lint": "biome check ./src" "lint": "biome check ./src"
}, },
@ -58,6 +59,8 @@
"@types/markdown-it": "^14.1.1", "@types/markdown-it": "^14.1.1",
"@types/mdast": "^4.0.4", "@types/mdast": "^4.0.4",
"@types/sanitize-html": "^2.11.0", "@types/sanitize-html": "^2.11.0",
"luau-path": "^0.1.0",
"npmluau": "^0.1.1",
"remark-github-admonitions-to-directives": "^1.0.5", "remark-github-admonitions-to-directives": "^1.0.5",
"sass": "^1.77.6", "sass": "^1.77.6",
"stylus": "^0.63.0" "stylus": "^0.63.0"

File diff suppressed because it is too large Load diff

View file

@ -1,52 +0,0 @@
/* This is a script to create a new post markdown file with front-matter */
import fs from "fs"
import path from "path"
function getDate() {
const today = new Date()
const year = today.getFullYear()
const month = String(today.getMonth() + 1).padStart(2, "0")
const day = String(today.getDate()).padStart(2, "0")
return `${year}-${month}-${day}`
}
const args = process.argv.slice(2)
if (args.length === 0) {
console.error(`Error: No filename argument provided
Usage: npm run new-post -- <filename>`)
process.exit(1) // Terminate the script and return error code 1
}
let fileName = args[0]
// Add .md extension if not present
const fileExtensionRegex = /\.(md|mdx)$/i
if (!fileExtensionRegex.test(fileName)) {
fileName += ".md"
}
const targetDir = "./src/content/posts/"
const fullPath = path.join(targetDir, fileName)
if (fs.existsSync(fullPath)) {
console.error(`ErrorFile ${fullPath} already exists `)
process.exit(1)
}
const content = `---
title: ${args[0]}
published: ${getDate()}
description: ''
image: ''
tags: []
category: ''
draft: false
---
`
fs.writeFileSync(path.join(targetDir, fileName), content)
console.log(`Post ${fullPath} created`)