kutake小站

个人博客 · 随便写点东西,记点笔记

把 WordPress 博客搬进 Hugo:迁移、构建与发布全记录

把 WordPress 博客搬进 Hugo:迁移、构建与发布全记录

这个博客原来跑在 WordPress 上。前几天我把它整个搬到了 Hugo,静态托管在 Cloudflare Pages 上,顺手把「写文章」这件事也重新做了一遍。这篇算是迁移完成后的第一篇,把整条流水线 从头到尾记一遍:数据怎么搬、Hugo 怎么构建、文章怎么写、发布怎么做,以及中间踩过的坑。 ...

2026-10-14 · 8 min · 3686 words · kutake

在有共同字段下的pydantic类转换不正确问题

在使用 Pydantic 进行数据验证和设置时,你可能会遇到一个问题:当多个类有共同字段时,Pydantic 可能无法正确地区分这些类。让我通过一个简单的例子来解释这个问题。 ...

2024-02-10 · 1 min · 493 words · kutake

基于Route来解决playwright的静态HTML资源加载问题

前因 由于python中没有方便快捷生成美观图片的方案,所以我使用了jinja2模板生成html后交给playwright生成网页图片,这其中,图片资源可以使用base64格式解决,而字体加载就难了。 ...

2024-02-10 · 2 min · 712 words · kutake

使用Github Workflows构建Tauri应用

下面这个例子是,当release分支有commit发生时,自动获取当前应用的版本信息,并使用缓存,分别构建前端和rust,并将构建好的包上传至指定tag的release上。在 platform处定义平台,这里我只选定了Win ...

2023-12-28 · 1 min · 404 words · kutake

[Tauri]Uint8Array与 Vec<u8>的坑

问题 当尝试传递 Uint8Array类型的图片数据给rust后端时,会发生 invalid type: map, expected a sequence 原因在于,tauri将 Uint8Array是作为对象而不是一个 Vec,要接受它,需要使用 HashMap<String, u8>来接收。 ...

2023-12-28 · 1 min · 133 words · kutake

Tokio异步task控制并发数量

使用tokio::sync::Semaphore 信号量可以保证在某一时刻最多运行指定数量的并发任务。 使用信号量时,需在初始化时指定信号灯(tokio中的SemaphorePermit)的数量,每当任务要执行时,将从中取走一个信号灯,当任务完成时(信号灯被drop)会归还信号灯。当某个任务要执行时,如果此时信号灯数量为0,则该任务将等待,直到有信号灯被归还。因此,信号量通常用来提供类似于限量的功能。 ...

2023-12-28 · 2 min · 832 words · kutake

Tauri 调用终端api

当你想从Tauri调用终端并运行类似 ls的命令的话,需要使用 @tauri-apps/api/shell的api,步骤如下 编辑 tauri.conf.json下的 tauri.allowlist.shell { "tauri": { "allowlist": { "shell": { "all": true, // enable all shell APIs "execute": true, // enable process spawn APIs "sidecar": true, // enable spawning sidecars "open": true // enable opening files/URLs using the default program } } } } 其他api暂时不讨论,只说 execute,假设我们需要使用git命令(案例来自官网) 编辑 scope定义好需要用到的命令,要是没有定义则无法调用 { "scope": [ { "name": "run-git-commit", "cmd": "git", "args": ["commit", "-m", { "validator": "\\S+" }] } ] } 开始调用该命令 import { Command } from '@tauri-apps/api/shell' const c = new Command('run-git-commit', ['commit', '-m', 'the commit message']) const std = await c.execute(); std.stderr std.stdout std.code std.signal 你可以将 args设置为 true来使js端可以传入任意参数 ...

2023-11-29 · 1 min · 472 words · kutake

Tauri 文件访问api

tauri支持从$APPCONFIG, $APPDATA, $APPLOCALDATA, $APPCACHE, $APPLOG, $AUDIO, $CACHE, $CONFIG, $DATA, $LOCALDATA, $DESKTOP, $DOCUMENT, $DOWNLOAD, $EXE, $FONT, $HOME, $PICTURE, $PUBLIC, $RUNTIME, $TEMPLATE, $VIDEO, $RESOURCE, $APP, $LOG, $TEMP 访问并读或文件夹和文件,具体措施如下 编辑 tauri.conf.json内的tauri.allowlist.fs { "tauri": { "allowlist": { "fs": { "all": true, // enable all FS APIs "readFile": true, "writeFile": true, "readDir": true, "copyFile": true, "createDir": true, "removeDir": true, "removeFile": true, "renameFile": true, "exists": true } } } } 可以直接 all: true 来开放所有tauri文件api,也可以单独开放某个api 编辑 scope开放具体访问权限 { "tauri": { "allowlist": { "fs": { "scope": ["$APPDATA/img/*"] } } } } 注意,这里开放了 $APPDATA下的 database访问权限,这样可以阻止程序访问任何路径,除了 database 从js中访问 import { readBinaryFile, BaseDirectory } from '@tauri-apps/api/fs'; // 可以是任何api // Read the image file in the `$APPDATA/avatar.png` path const contents = await readBinaryFile('img/avatar.png', { dir: BaseDirectory.AppData }); // 注意!一定要加上BaseDirectory.AppData 开放了哪个目录权限,就用 dir: BaseDirectory来指定访问路径,至少用绝对路径访问的方法我还没有找到,当然,这种相对路径访问的方式更加安全 ...

2023-11-29 · 1 min · 481 words · kutake

从创建项目到测试打包上传Pypi

前言 这是一次从创建项目到测试打包上传Pypi的过程,记录一下。 创建项目 这里我是用的是pdm这个包管理工具,创建项目的命令是pdm init,跟着引导一步步走,之后会生成一个pyproject.toml文件,里面有项目的一些基本信息,比如作者、版本号等。下面是一个示例: ...

2023-10-30 · 3 min · 1493 words · kutake

更优雅的包可用性检测

一般 try: import numpy except ImportError: print("numpy is not installed") 更推荐 from importlib.util import find_spec if find_spec("numpy") is not None: print("numpy is installed") else: print("numpy is not installed")

2023-08-06 · 1 min · 31 words · kutake