From 3cb9d7e1616f1aa64a4fccf9f38ae9e8d1a562a1 Mon Sep 17 00:00:00 2001 From: Haruki Date: Tue, 22 Aug 2023 17:46:47 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E4=B8=8A=E6=9B=B8=E3=81=8D=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E3=81=AAhtml,css,js=E3=82=A4=E3=83=99=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=81=AEkind(=E4=BB=AE)=E3=82=92=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nostrh/cmd/consts/consts.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/nostrh/cmd/consts/consts.go b/nostrh/cmd/consts/consts.go index e1c4906..da69610 100644 --- a/nostrh/cmd/consts/consts.go +++ b/nostrh/cmd/consts/consts.go @@ -1,8 +1,11 @@ package consts const ( - KindWebhostPicture = 1965 - KindWebhostHTML = 5392 - KindWebhostCSS = 5393 - KindWebhostJS = 5394 + KindWebhostPicture = 1965 + KindWebhostHTML = 5392 + KindWebhostCSS = 5393 + KindWebhostJS = 5394 + KindWebhostReplaceableHTML = 35392 + KindWebhostReplaceableCSS = 35393 + KindWebhostReplaceableJS = 35394 ) From 8678bfa8703d600e5deb634b23d02c103a4af872 Mon Sep 17 00:00:00 2001 From: Haruki Date: Thu, 24 Aug 2023 23:00:33 +0900 Subject: [PATCH 2/2] =?UTF-8?q?replaceable=E3=82=AA=E3=83=97=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nostrh/cmd/deploy/deploy.go | 73 ++++++++++++++++++++++++++++++------- nostrh/main.go | 17 ++++++++- 2 files changed, 76 insertions(+), 14 deletions(-) diff --git a/nostrh/cmd/deploy/deploy.go b/nostrh/cmd/deploy/deploy.go index 73f98f2..731de13 100644 --- a/nostrh/cmd/deploy/deploy.go +++ b/nostrh/cmd/deploy/deploy.go @@ -18,21 +18,41 @@ import ( "golang.org/x/net/html" ) -func pathToKind(path string) (int, error) { +func pathToKind(path string, replaceable bool) (int, error) { + // パスを分割 separatedPath := strings.Split(path, ".") + // 拡張子を取得 ex := separatedPath[len(separatedPath)-1] + // replaceable(NIP-33)の場合はReplaceableなkindを返す switch ex { case "html": - return consts.KindWebhostHTML, nil + if replaceable { + return consts.KindWebhostHTML, nil + } else { + return consts.KindWebhostReplaceableHTML, nil + } case "css": - return consts.KindWebhostCSS, nil + if replaceable { + return consts.KindWebhostReplaceableCSS, nil + } else { + return consts.KindWebhostCSS, nil + } case "js": - return consts.KindWebhostJS, nil + if replaceable { + return consts.KindWebhostReplaceableJS, nil + } else { + return consts.KindWebhostJS, nil + } default: - return 0, nil + return 0, fmt.Errorf("Invalid path") } } +// Replaceableにする場合のidentifier(dタグ)を取得 +func getReplaceableIdentifier(indexHtmlIdentifier, filePath string) string { + return indexHtmlIdentifier + filePath +} + var nostrEventsQueue []*nostr.Event func addNostrEventQueue(event *nostr.Event) { @@ -117,7 +137,7 @@ func isValidFileType(str string) bool { return strings.HasSuffix(str, ".html") || strings.HasSuffix(str, ".css") || strings.HasSuffix(str, ".js") } -func Deploy(basePath string) (string, error) { +func Deploy(basePath string, replaceable bool, htmlIdentifier string) (string, error) { // 引数からデプロイしたいサイトのパスを受け取る。 filePath := filepath.Join(basePath, "index.html") @@ -147,10 +167,16 @@ func Deploy(basePath string) (string, error) { return "", err } + // htmlIdentifierの存在チェック + if (len(htmlIdentifier) < 1) { + // htmlIdentifier + } + + // index.htmlファイル内に記述されている他Assetのパスから実際のデータを取得。 // 取得してきたデータをeventにしてIDを取得。 // リンクの解析と変換 - convertLinks(priKey, pubKey, basePath, doc) + convertLinks(priKey, pubKey, basePath, replaceable, htmlIdentifier, doc) // 更新されたHTML var buf bytes.Buffer @@ -158,8 +184,20 @@ func Deploy(basePath string) (string, error) { strHtml := buf.String() + // index.htmlのkindを設定 + indexHtmlKind := consts.KindWebhostHTML + if replaceable { + indexHtmlKind = consts.KindWebhostReplaceableHTML + } + + // Tagsを追加 + tags := nostr.Tags{} + if replaceable { + tags = tags.AppendUnique(nostr.Tag{"d", htmlIdentifier}) + } + // Eventを生成しキューに追加 - event, err := getEvent(priKey, pubKey, strHtml, consts.KindWebhostHTML) + event, err := getEvent(priKey, pubKey, strHtml, indexHtmlKind, tags) if err != nil { fmt.Println("❌ Failed to get public key:", err) return "", err @@ -170,15 +208,16 @@ func Deploy(basePath string) (string, error) { return publishEventsFromQueue() } -func convertLinks(priKey, pubKey, basePath string, n *html.Node) { +func convertLinks(priKey, pubKey, basePath string, replaceable bool, indexHtmlIdentifier string, n *html.Node) { //