From f45290221e4b9120858d86c33a05c8d35a93eecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Wed, 10 Apr 2024 15:12:59 +0900 Subject: [PATCH] =?UTF-8?q?=E5=A4=89=E3=81=AA=E3=82=A8=E3=83=B3=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=87=E3=82=A3=E3=83=B3=E3=82=B0=E3=81=AE=E5=A4=89?= =?UTF-8?q?=E6=8F=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 ++ go.sum | 2 ++ src/getpage.go | 68 +++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index a74783f..6e49e28 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,5 @@ module gitler.moe/suwako/hozonsite go 1.20 require gitler.moe/suwako/goliblocale v1.0.0 + +require golang.org/x/text v0.14.0 // indirect diff --git a/go.sum b/go.sum index 7642e2e..f49f910 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ gitler.moe/suwako/goliblocale v1.0.0 h1:QiQKNzdgpavwmAaYhAb5pth0I6qS8IJ7q2hYAgpXacU= gitler.moe/suwako/goliblocale v1.0.0/go.mod h1:pdv9Go5taevY8ClBOA+oLXjGap7G1RmIVKUMF8HSJmU= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= diff --git a/src/getpage.go b/src/getpage.go index 6c8460d..d4fea26 100644 --- a/src/getpage.go +++ b/src/getpage.go @@ -5,7 +5,11 @@ import ( "fmt" "net/http" "io" + "regexp" "strings" + + "golang.org/x/text/encoding/japanese" + "golang.org/x/text/transform" ) // URLでパラメートル(?、=等)がある場合 @@ -22,7 +26,8 @@ func Getpage (url string, path string) { fmt.Println("CURLエラー:", err) return } - defer curl.Body.Close() // ソフトの終了する時に実行する + // ソフトの終了する時に実行する + defer curl.Body.Close() // ページの内容を読み込む body, err2 := io.ReadAll(curl.Body) @@ -31,17 +36,62 @@ func Getpage (url string, path string) { return } - // 空index.htmlファイルを創作する - fn, err3 := os.Create(path + "/index.html") - if err3 != nil { - fmt.Println("ファイルの創作エラー:", err3) + // Content-TypeヘッダーはUTF-8又は駄目のエンコーディングかの確認 + checkJis := `(?i)