diff --git a/example/public/DALL·E Ostrich Hero.png b/example/public/DALL·E Ostrich Hero.png new file mode 100644 index 0000000..835e0dd Binary files /dev/null and b/example/public/DALL·E Ostrich Hero.png differ diff --git a/example/public/DALL·E Ostrich Illustration (1).png b/example/public/DALL·E Ostrich Illustration (1).png new file mode 100644 index 0000000..89d1971 Binary files /dev/null and b/example/public/DALL·E Ostrich Illustration (1).png differ diff --git a/example/public/DALL·E Ostrich Illustration (2).png b/example/public/DALL·E Ostrich Illustration (2).png new file mode 100644 index 0000000..4119bd1 Binary files /dev/null and b/example/public/DALL·E Ostrich Illustration (2).png differ diff --git a/example/public/DALL·E Ostrich Illustration.png b/example/public/DALL·E Ostrich Illustration.png new file mode 100644 index 0000000..8390e52 Binary files /dev/null and b/example/public/DALL·E Ostrich Illustration.png differ diff --git a/example/public/DALL·E Ostrich on Jamaican Beach.png b/example/public/DALL·E Ostrich on Jamaican Beach.png new file mode 100644 index 0000000..d655657 Binary files /dev/null and b/example/public/DALL·E Ostrich on Jamaican Beach.png differ diff --git a/example/src/App.tsx b/example/src/App.tsx index 2beb3d7..0632516 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,41 +1,15 @@ -import { useEffect, useMemo } from "react"; import { H1 } from "./components/H1"; import { Link } from "./components/Link"; function App() { - const htmlId = useMemo(() => window.location.pathname.split("/")[2], []); - const cssId = useMemo( - () => Array.from(document.styleSheets)[0].href?.split("/").slice(-1)[0], - [] - ); - const jsId = useMemo( - () => Array.from(document.scripts)[0].src?.split("/").slice(-1)[0], - [] - ); - - useEffect(() => { - console.log(Array.from(document.styleSheets)); - }, []); - return ( -
-
+
+

Nostr
WebHost

-
-

- Relay URL:{" "} - - wss://hostr.cc - -

-

HTML ID: {htmlId}

-

CSS ID: {cssId}

-

Javascript ID: {jsId}

-

GitHub:{" "} @@ -56,10 +30,36 @@ function App() { https://github.com/studiokaiji

+

Lightning Address: floppystore07@walletofsatoshi.com

+
+ +
+ ↓↓ CUTE OSTRICHES GALLERY ↓↓ +
+ +
+ + + + +
-

- 😩{"<"}Hmmm... I want to ride an ostrich... -

); diff --git a/example/src/index.css b/example/src/index.css index 17de24c..17b85dd 100644 --- a/example/src/index.css +++ b/example/src/index.css @@ -5,4 +5,5 @@ body { cursor: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHZpZXdCb3g9IjAgMCA0MCA0MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGNpcmNsZSBjeD0iMjAiIGN5PSIyMCIgcj0iMjAiIGZpbGw9IiM4RTMwRUIiLz4KPC9zdmc+Cg==, auto); height: 100vh; + @apply bg-primary; } \ No newline at end of file diff --git a/example/tailwind.config.js b/example/tailwind.config.js index 97026f1..baa4fb1 100644 --- a/example/tailwind.config.js +++ b/example/tailwind.config.js @@ -9,6 +9,10 @@ export default { colors: { primary: "#8e30eb", }, + backgroundImage: { + "rainbow-gradient": + "linear-gradient(to right,#e60000,#f39800,#fff100,#009944,#0068b7,#1d2088,#920783,#e60000)", + }, }, }, plugins: [], diff --git a/hostr/cmd/deploy/deploy.go b/hostr/cmd/deploy/deploy.go index ff19deb..1d05d86 100644 --- a/hostr/cmd/deploy/deploy.go +++ b/hostr/cmd/deploy/deploy.go @@ -3,144 +3,26 @@ package deploy import ( "bufio" "bytes" - "context" "fmt" "net/url" "os" "path/filepath" "strings" - "sync" "github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr/nip19" "github.com/studiokaiji/nostr-webhost/hostr/cmd/consts" "github.com/studiokaiji/nostr-webhost/hostr/cmd/keystore" "github.com/studiokaiji/nostr-webhost/hostr/cmd/relays" - "github.com/studiokaiji/nostr-webhost/hostr/cmd/tools" + "golang.org/x/exp/slices" "golang.org/x/net/html" ) -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": - if replaceable { - return consts.KindWebhostHTML, nil - } else { - return consts.KindWebhostReplaceableHTML, nil - } - case "css": - if replaceable { - return consts.KindWebhostReplaceableCSS, nil - } else { - return consts.KindWebhostCSS, nil - } - case "js": - if replaceable { - return consts.KindWebhostReplaceableJS, nil - } else { - return consts.KindWebhostJS, nil - } - default: - return 0, fmt.Errorf("Invalid path") - } -} - -// Replaceableにする場合のidentifier(dタグ)を取得 -func getReplaceableIdentifier(indexHtmlIdentifier, filePath string) string { - return indexHtmlIdentifier + "/" + filePath[1:] -} - -var nostrEventsQueue []*nostr.Event - -func addNostrEventQueue(event *nostr.Event) { - nostrEventsQueue = append(nostrEventsQueue, event) -} - -var allRelays []string - -func publishEventsFromQueue(replaceable bool) (string, string) { - ctx := context.Background() - - fmt.Println("Publishing...") - - // 各リレーに接続 - var relays []*nostr.Relay - - for _, url := range allRelays { - relay, err := nostr.RelayConnect(ctx, url) - if err != nil { - fmt.Println("❌ Failed to connect to:", url) - continue - } - relays = append(relays, relay) - } - - // Publishの進捗状況を表示 - allEventsCount := len(nostrEventsQueue) - uploadedFilesCount := 0 - - var wg sync.WaitGroup - - go func() { - wg.Add(1) - tools.DisplayProgressBar(&uploadedFilesCount, &allEventsCount) - wg.Done() - }() - - var mutex sync.Mutex - - // リレーへpublish - for _, ev := range nostrEventsQueue { - wg.Add(1) - go func(event *nostr.Event) { - for _, relay := range relays { - _, err := relay.Publish(ctx, *event) - if err != nil { - fmt.Println(err) - continue - } - } - mutex.Lock() // ロックして排他制御 - uploadedFilesCount++ // カウントアップ - mutex.Unlock() // ロック解除 - wg.Done() // ゴルーチンの終了を通知 - }(ev) - } - - wg.Wait() - - if uploadedFilesCount < allEventsCount { - fmt.Println("Failed to deploy", allEventsCount-uploadedFilesCount, "files.") - } - - indexEvent := nostrEventsQueue[len(nostrEventsQueue)-1] - - encoded := "" - if !replaceable { - if enc, err := nip19.EncodeEvent(indexEvent.ID, allRelays, indexEvent.PubKey); err == nil { - encoded = enc - } else { - fmt.Println("❌ Failed to covert nevent:", err) - } - } - - return indexEvent.ID, encoded -} - func isExternalURL(urlStr string) bool { u, err := url.Parse(urlStr) return err == nil && u.Scheme != "" && u.Host != "" } -func isValidFileType(str string) bool { - return strings.HasSuffix(str, ".html") || strings.HasSuffix(str, ".css") || strings.HasSuffix(str, ".js") -} - func Deploy(basePath string, replaceable bool, htmlIdentifier string) (string, string, error) { // 引数からデプロイしたいサイトのパスを受け取る。 filePath := filepath.Join(basePath, "index.html") @@ -187,6 +69,15 @@ func Deploy(basePath string, replaceable bool, htmlIdentifier string) (string, s // リレーを取得 allRelays, err = relays.GetAllRelays() if err != nil { + fmt.Println("❌ Failed to get all relays:", err) + return "", "", err + } + + + // basePath以下のMedia Fileのパスを全て羅列しアップロード + err = uploadAllValidStaticMediaFiles(priKey, pubKey, basePath) + if err != nil { + fmt.Println("❌ Failed to upload media:", err) return "", "", err } @@ -225,56 +116,93 @@ func Deploy(basePath string, replaceable bool, htmlIdentifier string) (string, s return eventId, encoded, err } -func convertLinks(priKey, pubKey, basePath string, replaceable bool, indexHtmlIdentifier string, n *html.Node) { - //