OSDN Git Service

[update] : タイトル書き換えを追加 master origin/master
authorhayao <hayao@fascode.net>
Wed, 2 Feb 2022 12:48:04 +0000 (21:48 +0900)
committerhayao <hayao@fascode.net>
Wed, 2 Feb 2022 12:48:04 +0000 (21:48 +0900)
blog/new-post.v

index 63814a5..d442ed1 100644 (file)
@@ -2,6 +2,7 @@ import os
 import ui
 import time
 import strconv as strc
+import regex
 //import eventbus
 
 const (
@@ -137,6 +138,28 @@ fn create_article(url string, title string){
                ui.message_box(result.output)
        }
 
+       mut re := regex.regex_opt('^title: ".*"$') or {return}
+       mut path := os.resource_abs_path("./src/content/${filename}")
+       println(path)
+       mut article_md := os.read_lines(path) or {
+               ui.message_box("Failed to open \"$path\"")
+               return
+               //exit(1)
+       }
+
+       for cnt,line in article_md{
+               if re.matches_string(line){
+                       eprintln("書き換え対象を${cnt}行目に発見")
+                       article_md[cnt] = re.replace(line, 'title: "$title"')
+                       eprintln("${line} ==> title: \"$title\"")
+                       break
+               }
+       }
+
+       os.write_file(path, article_md.join("\n")) or {
+               ui.message_box("Failed to write to $path")
+       }
+
        exit(0)
 }