diff --git a/.air.toml b/.air.toml index 62ef533..85e2ea5 100644 --- a/.air.toml +++ b/.air.toml @@ -5,7 +5,7 @@ tmp_dir = "tmp" [build] args_bin = [] bin = "./tmp/main" - cmd = "go build -tags=nocache -o ./tmp/main ." + cmd = "just debug-build" delay = 0 exclude_dir = ["tmp", "vendor", "testdata", "node_modules"] exclude_file = [] diff --git a/.gitignore b/.gitignore index dd150ab..473ca34 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ njump local/ tmp/ node_modules/ -.sass-cache/ \ No newline at end of file +.sass-cache/ +static/tailwind-bundle.min.css diff --git a/justfile b/justfile index 5fdf60e..bd56568 100644 --- a/justfile +++ b/justfile @@ -1,4 +1,7 @@ -build: +dev: + TAILWIND_DEBUG=true go run . + +build: tailwind CC=$(which musl-gcc) go build -ldflags='-s -w -linkmode external -extldflags "-static"' -o ./njump deploy: build @@ -7,8 +10,11 @@ deploy: build ssh turgot 'mv njump/njump-new njump/njump' ssh root@turgot 'systemctl start njump' -refresh_build: scss prettier +debug-build: tailwind go build -tags=nocache -o ./tmp/main . prettier: prettier -w templates/*.html + +tailwind: + tailwind -i tailwind.css -o static/tailwind-bundle.min.css --minify diff --git a/main.go b/main.go index 2bb9b86..0ebb68e 100644 --- a/main.go +++ b/main.go @@ -3,8 +3,11 @@ package main import ( "context" "embed" + "fmt" + "html/template" "net/http" "os" + "strings" "time" "github.com/kelseyhightower/envconfig" @@ -14,8 +17,9 @@ import ( type Settings struct { Port string `envconfig:"PORT" default:"2999"` - DiskCachePath string `envconfig:"DISK_CACHE_PATH" default:"/tmp/njump-cache"` Domain string `envconfig:"DOMAIN" default:"njump.me"` + DiskCachePath string `envconfig:"DISK_CACHE_PATH" default:"/tmp/njump-cache"` + TailwindDebug bool `envconfig:"TAILWIND_DEBUG"` } //go:embed static/* @@ -25,8 +29,9 @@ var static embed.FS var templates embed.FS var ( - s Settings - log = zerolog.New(os.Stderr).Output(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger() + s Settings + log = zerolog.New(os.Stderr).Output(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger() + tailwindDebugStuff template.HTML ) func updateArchives(ctx context.Context) { @@ -56,6 +61,25 @@ func main() { } } + // if we're in tailwind debug mode, initialize the runtime tailwind stuff + if s.TailwindDebug { + configb, err := os.ReadFile("tailwind.config.js") + if err != nil { + log.Fatal().Err(err).Msg("failed to load tailwind.config.js") + return + } + config := strings.Replace(string(configb), "module.exports", "tailwind.config", 1) + + styleb, err := os.ReadFile("tailwind.css") + if err != nil { + log.Fatal().Err(err).Msg("failed to load tailwind.css") + return + } + style := string(styleb) + + tailwindDebugStuff = template.HTML(fmt.Sprintf("", config, style)) + } + // initialize disk cache defer cache.initialize()() diff --git a/pages.go b/pages.go index 6d00337..edf7783 100644 --- a/pages.go +++ b/pages.go @@ -28,12 +28,11 @@ var ( //tmpl:bind head_common.html type HeadCommonPartial struct { - IsProfile bool + IsProfile bool + TailwindDebugStuff template.HTML } -func (*HeadCommonPartial) TemplateText() string { - return tmplHeadCommon -} +func (*HeadCommonPartial) TemplateText() string { return tmplHeadCommon } var ( //go:embed templates/top.html @@ -44,9 +43,7 @@ var ( //tmpl:bind top.html type TopPartial struct{} -func (*TopPartial) TemplateText() string { - return tmplTop -} +func (*TopPartial) TemplateText() string { return tmplTop } var ( //go:embed templates/details.html @@ -68,9 +65,7 @@ type DetailsPartial struct { KindDescription string } -func (*DetailsPartial) TemplateText() string { - return tmplDetails -} +func (*DetailsPartial) TemplateText() string { return tmplDetails } var ( //go:embed templates/clients.html @@ -83,9 +78,7 @@ type ClientsPartial struct { Clients []ClientReference } -func (*ClientsPartial) TemplateText() string { - return tmplClients -} +func (*ClientsPartial) TemplateText() string { return tmplClients } var ( //go:embed templates/footer.html @@ -96,9 +89,7 @@ var ( //tmpl:bind footer.html type FooterPartial struct{} -func (*FooterPartial) TemplateText() string { - return tmplFooter -} +func (*FooterPartial) TemplateText() string { return tmplFooter } var ( //go:embed templates/telegram_instant_view.html @@ -119,9 +110,7 @@ type TelegramInstantViewPage struct { CreatedAt string } -func (*TelegramInstantViewPage) TemplateText() string { - return tmplTelegramInstantView -} +func (*TelegramInstantViewPage) TemplateText() string { return tmplTelegramInstantView } var ( //go:embed templates/homepage.html @@ -139,9 +128,7 @@ type HomePage struct { LastNotes []string } -func (*HomePage) TemplateText() string { - return tmplHomePage -} +func (*HomePage) TemplateText() string { return tmplHomePage } var ( //go:embed templates/archive.html @@ -163,9 +150,7 @@ type ArchivePage struct { PrevPage int } -func (*ArchivePage) TemplateText() string { - return tmplArchive -} +func (*ArchivePage) TemplateText() string { return tmplArchive } var ( //go:embed templates/other.html @@ -185,9 +170,7 @@ type OtherPage struct { KindDescription string } -func (*OtherPage) TemplateText() string { - return tmplOther -} +func (*OtherPage) TemplateText() string { return tmplOther } var ( //go:embed templates/note.html @@ -225,9 +208,7 @@ type NotePage struct { VideoType string } -func (*NotePage) TemplateText() string { - return tmplNote -} +func (*NotePage) TemplateText() string { return tmplNote } var ( //go:embed templates/profile.html @@ -258,9 +239,7 @@ type ProfilePage struct { Title string } -func (*ProfilePage) TemplateText() string { - return tmplProfile -} +func (*ProfilePage) TemplateText() string { return tmplProfile } var ( //go:embed templates/relay.html @@ -281,9 +260,7 @@ type RelayPage struct { ModifiedAt string } -func (*RelayPage) TemplateText() string { - return tmplRelay -} +func (*RelayPage) TemplateText() string { return tmplRelay } var ( //go:embed templates/sitemap.xml @@ -309,6 +286,4 @@ type SitemapPage struct { Data []string } -func (*SitemapPage) TemplateText() string { - return tmplSitemap -} +func (*SitemapPage) TemplateText() string { return tmplSitemap } diff --git a/render_archive.go b/render_archive.go index a552477..3ddd628 100644 --- a/render_archive.go +++ b/render_archive.go @@ -85,7 +85,7 @@ func renderArchive(w http.ResponseWriter, r *http.Request) { if !isSitemap { ArchiveTemplate.Render(w, &ArchivePage{ - HeadCommonPartial: HeadCommonPartial{IsProfile: false}, + HeadCommonPartial: HeadCommonPartial{IsProfile: false, TailwindDebugStuff: tailwindDebugStuff}, Title: title, PathPrefix: pathPrefix, diff --git a/render_event.go b/render_event.go index e3e84aa..9cf1d50 100644 --- a/render_event.go +++ b/render_event.go @@ -239,7 +239,7 @@ func renderEvent(w http.ResponseWriter, r *http.Request) { }) case Note: err = NoteTemplate.Render(w, &NotePage{ - HeadCommonPartial: HeadCommonPartial{IsProfile: false}, + HeadCommonPartial: HeadCommonPartial{IsProfile: false, TailwindDebugStuff: tailwindDebugStuff}, DetailsPartial: detailsData, ClientsPartial: ClientsPartial{ Clients: generateClientList(code, data.event), @@ -268,7 +268,7 @@ func renderEvent(w http.ResponseWriter, r *http.Request) { }) case Other: err = OtherTemplate.Render(w, &OtherPage{ - HeadCommonPartial: HeadCommonPartial{IsProfile: false}, + HeadCommonPartial: HeadCommonPartial{IsProfile: false, TailwindDebugStuff: tailwindDebugStuff}, DetailsPartial: detailsData, IsParameterizedReplaceable: data.event.Kind >= 30000 && data.event.Kind < 40000, Naddr: data.naddr, diff --git a/render_homepage.go b/render_homepage.go index 3dc490f..f8f3f9e 100644 --- a/render_homepage.go +++ b/render_homepage.go @@ -7,7 +7,7 @@ import ( func renderHomepage(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "max-age=3600") err := HomePageTemplate.Render(w, &HomePage{ - HeadCommonPartial: HeadCommonPartial{IsProfile: false}, + HeadCommonPartial: HeadCommonPartial{IsProfile: false, TailwindDebugStuff: tailwindDebugStuff}, Host: s.Domain, }) if err != nil { diff --git a/render_profile.go b/render_profile.go index f37dde7..7450cbc 100644 --- a/render_profile.go +++ b/render_profile.go @@ -31,7 +31,7 @@ func renderProfile(w http.ResponseWriter, r *http.Request, code string) { if !isSitemap { err = ProfileTemplate.Render(w, &ProfilePage{ - HeadCommonPartial: HeadCommonPartial{IsProfile: true}, + HeadCommonPartial: HeadCommonPartial{IsProfile: true, TailwindDebugStuff: tailwindDebugStuff}, DetailsPartial: DetailsPartial{ HideDetails: true, CreatedAt: data.createdAt, diff --git a/render_relay.go b/render_relay.go index 4592ada..5e25a6e 100644 --- a/render_relay.go +++ b/render_relay.go @@ -64,7 +64,7 @@ func renderRelayPage(w http.ResponseWriter, r *http.Request) { if !isSitemap { RelayTemplate.Render(w, &RelayPage{ - HeadCommonPartial: HeadCommonPartial{IsProfile: false}, + HeadCommonPartial: HeadCommonPartial{IsProfile: false, TailwindDebugStuff: tailwindDebugStuff}, ClientsPartial: ClientsPartial{ Clients: generateRelayBrowserClientList(hostname), }, diff --git a/tailwind.config.js b/tailwind.config.js new file mode 100644 index 0000000..1456e5d --- /dev/null +++ b/tailwind.config.js @@ -0,0 +1,28 @@ +module.exports = { + content: ['./templates/*.html', './*.go'], + darkMode: ['class', '.theme--dark'], + theme: { + extend: { + fontFamily: { + sans: ['Helvetica', 'ui-sans-serif', 'system-ui'] + }, + colors: { + lavender: '#fdf0f5', + strongpink: '#e32a6d', + crimson: '#bc1150', + garnet: '#42091e' + }, + typography: ({theme}) => ({ + /* for markdown html content */ + DEFAULT: { + css: { + '--tw-prose-headings': theme('colors.strongpink'), + '--tw-prose-invert-headings': theme('colors.strongpink'), + '--tw-prose-links': theme('colors.gray[700]'), + '--tw-prose-invert-links': theme('colors.neutral[50]') + } + } + }) + } + } +} diff --git a/tailwind.css b/tailwind.css new file mode 100644 index 0000000..4efa6fe --- /dev/null +++ b/tailwind.css @@ -0,0 +1,18 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; +@layer utilities { + .imgclip { + clip-path: url(#svg-shape); + } + .gradient { + mask-image: linear-gradient( + to bottom, + rgb(0, 0, 0) 50%, + rgba(0, 0, 0, 0) 100% + ); + } + .safari { + margin: 1cm 3cm; + } +} diff --git a/templates/archive.html b/templates/archive.html index a7972ea..b136f1f 100644 --- a/templates/archive.html +++ b/templates/archive.html @@ -4,7 +4,7 @@