-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update bookmarklet without Node.js
and change HTTP server's port again
- Loading branch information
Showing
13 changed files
with
207 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.PHONY: build-server | ||
build-server: | ||
go build -o bin/server cmd/server/main.go | ||
|
||
.PHONY: build-bookmarklet | ||
build-bookmarklet: | ||
go build -o bin/bookmarklet cmd/bookmarklet/main.go | ||
|
||
.PHONY: build-tray | ||
build-tray: | ||
go build -o bin/tray cmd/tray/main.go | ||
|
||
.PHONY: bundle-macos | ||
bundle-macos: | ||
cd macos && ./bundle.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package bookmarklet | ||
|
||
import _ "embed" | ||
|
||
//go:embed src.js | ||
var SourceFile string |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"fmt" | ||
"log" | ||
"net/url" | ||
"os" | ||
"strings" | ||
"text/template" | ||
|
||
"github.com/charmbracelet/huh" | ||
|
||
"github.com/fedragon/bookmarkd/bookmarklet" | ||
"github.com/fedragon/bookmarkd/internal" | ||
) | ||
|
||
func main() { | ||
var address string | ||
var vault string | ||
var folder string | ||
|
||
form := huh.NewForm( | ||
huh.NewGroup( | ||
huh.NewInput(). | ||
Title("HTTP server address"). | ||
Placeholder("http://localhost:11235"). | ||
Value(&address), | ||
huh.NewInput(). | ||
Title("Vault"). | ||
Placeholder("my-vault"). | ||
Value(&vault), | ||
huh.NewInput(). | ||
Title("Folder"). | ||
Placeholder("Clippings"). | ||
Value(&folder), | ||
), | ||
) | ||
|
||
if err := form.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
tpl, err := template.New("bookmarklet").Parse(bookmarklet.SourceFile) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
writer := bytes.NewBuffer([]byte{}) | ||
if err := tpl.Execute( | ||
writer, | ||
struct { | ||
Address string | ||
Vault string | ||
Folder string | ||
}{ | ||
Address: address, | ||
Vault: vault, | ||
Folder: folder, | ||
}, | ||
); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
encoded := url.QueryEscape(strings.TrimSpace(writer.String())) | ||
content := fmt.Sprintf( | ||
"javascript:%s", | ||
internal.EncodeURIComponent( | ||
fmt.Sprintf( | ||
"(function(){%s})();", | ||
encoded, | ||
), | ||
), | ||
) | ||
if err := os.WriteFile("bookmarklet.js", []byte(content), 0644); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package internal | ||
|
||
type Config struct { | ||
HttpAddress string `envconfig:"BOOKMARKD_HTTP_ADDRESS" default:"0.0.0.0:20918"` | ||
HttpAddress string `envconfig:"BOOKMARKD_HTTP_ADDRESS" default:"0.0.0.0:11235"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package internal | ||
|
||
import "strings" | ||
|
||
func EncodeURIComponent(str string) string { | ||
result := strings.Replace(str, "+", "%20", -1) | ||
result = strings.Replace(result, "%21", "!", -1) | ||
result = strings.Replace(result, "%27", "'", -1) | ||
result = strings.Replace(result, "%28", "(", -1) | ||
result = strings.Replace(result, "%29", ")", -1) | ||
result = strings.Replace(result, "%2A", "*", -1) | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters