mirror of
https://github.com/fengxxc/wechatmp2markdown.git
synced 2026-04-21 03:07:42 +08:00
fix: linux下标题包含斜杠导致被分成两级目录的bug(使用∕替代)
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,6 +1,6 @@
|
|||||||
BUILD_ENV := CGO_ENABLED=0
|
BUILD_ENV := CGO_ENABLED=0
|
||||||
APP=wechatmp2markdown
|
APP=wechatmp2markdown
|
||||||
VERSION=v1.1.9
|
VERSION=v1.1.10
|
||||||
|
|
||||||
# linux or mac 环境编译
|
# linux or mac 环境编译
|
||||||
# make [cmd]
|
# make [cmd]
|
||||||
|
|||||||
@@ -83,7 +83,11 @@ markdown和图片文件将保存在 `D:\wechatmp_bak\gitcode操你妈\` 下
|
|||||||
> "*" -> "⁎"
|
> "*" -> "⁎"
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
> 在linux环境下,使用CLI模式,需要为程序赋予可执行与写权限,例如:` chmod +xw wechatmp2markdown-v1.1.9_linux_amd64`
|
> 在linux环境下,使用CLI模式,需要为程序赋予可执行与写权限,例如:` chmod +xw wechatmp2markdown-v1.1.10_linux_amd64`;
|
||||||
|
> 以及,文件或路径名不能包含以下任何字符:/(正斜杠),当标题包含以上字符时,本程序将用相似的Unicode字符进行替换,具体替换规则为:
|
||||||
|
> ```
|
||||||
|
> "/" -> "∕"
|
||||||
|
> ```
|
||||||
|
|
||||||
### web server 模式
|
### web server 模式
|
||||||
通过web服务使用
|
通过web服务使用
|
||||||
@@ -105,7 +109,7 @@ markdown和图片文件将保存在 `D:\wechatmp_bak\gitcode操你妈\` 下
|
|||||||
浏览器访问:`localhost:8964?url=https://mp.weixin.qq.com/s/a=1&b=2&image=save`,
|
浏览器访问:`localhost:8964?url=https://mp.weixin.qq.com/s/a=1&b=2&image=save`,
|
||||||
将返回一个zip文件
|
将返回一个zip文件
|
||||||
|
|
||||||
> 在linux环境下,使用web server模式,需要为程序赋予可执行权限,例如:` chmod +x wechatmp2markdown-v1.1.9_linux_amd64`
|
> 在linux环境下,使用web server模式,需要为程序赋予可执行权限,例如:` chmod +x wechatmp2markdown-v1.1.10_linux_amd64`
|
||||||
|
|
||||||
## 开发
|
## 开发
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|||||||
@@ -57,12 +57,26 @@ func legalizationFilenameForWindows(name string) string {
|
|||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// linux下, 文件名包含非法字符时, 用相似的Unicode字符进行替换
|
||||||
|
func legalizationFilenameForLinux(name string) string {
|
||||||
|
// Linux文件名不能包含这些字符
|
||||||
|
invalidChars := regexp.MustCompile(`[\/]`)
|
||||||
|
|
||||||
|
// 如果包含非法字符,则替换
|
||||||
|
if invalidChars.MatchString(name) {
|
||||||
|
name = strings.ReplaceAll(name, "/", "∕")
|
||||||
|
}
|
||||||
|
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
// FormatAndSave fomat article and save to local file
|
// FormatAndSave fomat article and save to local file
|
||||||
func FormatAndSave(article parse.Article, filePath string) error {
|
func FormatAndSave(article parse.Article, filePath string) error {
|
||||||
// basrPath := filepath.Join(filePath, )
|
// basrPath := filepath.Join(filePath, )
|
||||||
var basePath string
|
var basePath string
|
||||||
var fileName string
|
var fileName string
|
||||||
var isWin bool = runtime.GOOS == "windows"
|
var isWin bool = runtime.GOOS == "windows"
|
||||||
|
var isLinux bool = runtime.GOOS == "linux"
|
||||||
var separator string
|
var separator string
|
||||||
if isWin {
|
if isWin {
|
||||||
separator = "\\"
|
separator = "\\"
|
||||||
@@ -84,6 +98,8 @@ func FormatAndSave(article parse.Article, filePath string) error {
|
|||||||
title := strings.TrimSpace(article.Title.Val.(string))
|
title := strings.TrimSpace(article.Title.Val.(string))
|
||||||
if isWin {
|
if isWin {
|
||||||
title = legalizationFilenameForWindows(title)
|
title = legalizationFilenameForWindows(title)
|
||||||
|
} else if isLinux {
|
||||||
|
title = legalizationFilenameForLinux(title)
|
||||||
}
|
}
|
||||||
// title := "thisistitle"
|
// title := "thisistitle"
|
||||||
basePath = filepath.Join(filePath, title)
|
basePath = filepath.Join(filePath, title)
|
||||||
|
|||||||
Reference in New Issue
Block a user