diff --git a/less/pad-theme.less b/less/pad-theme.less index 94276cd..ee8c041 100644 --- a/less/pad-theme.less +++ b/less/pad-theme.less @@ -1,217 +1,368 @@ @lightBG: #ffffff; @lightTextColor: #000; @lightLinkColor: #444; @lightNavBG: #fff; @lightNavHoverBG: #f6f6f6; @lightNavBorder: #ccc; @darkBG: #222222; @darkTextColor: #ffffff; @darkLinkColor: #ccc; @darkNavBG: #393939; @darkNavHoverBG: #555; @darkNavBorder: #333; .pad-theme-transition { -moz-transition-property: background-color, color; -webkit-transition-property: background-color, color; -o-transition-property: background-color, color; transition-property: background-color, color; .transition-duration(0.25s); } body#pad-sub #posts, .atoms { h3 { a { color: @lightTextColor; &:hover { color: darken(@lightTextColor, 10%); } } } h3, h4 { a { color: @lightTextColor; &:hover { color: darken(@lightTextColor, 10%); } } } date, .electron { color: #999; } a.action, a { color: @lightLinkColor; &:hover { color: darken(@lightLinkColor, 10%); } } } body#pad, body#pad-sub { .pad-theme-transition; &.light { background-color: @lightBG; color: @lightTextColor; #tools { .pad-theme-transition; background-color: transparent; h1 { a { color: @headerTextColor; } } #belt { a, button { color: #000; } } .tool { &#status { color: #999; } } .hidden { &#wc { color: #777; } } a:hover, a:active { background-color: transparent; color: @lightLinkColor; } } .modal { border-color: @lightNavBorder; background: @lightNavBG; } } &.dark { background-color: @darkBG; color: @darkTextColor; #tools { .pad-theme-transition; background-color: #262626; h1 { a { color: @darkTextColor; } } #belt { a, button { color: white; } } .tool { &#status { color: #666; } } .hidden { &#wc { color: #ececec; } } a:hover, a:active { background-color: transparent; color: @darkLinkColor; } nav { &> ul > li a { color: @darkTextColor; } ul { ul { background: @darkNavBG; border-color: @darkNavBorder; } li { &.current-user { color: #fff; } &.selected { a { color: #777; } } } li:hover { background: @darkNavHoverBG; } } } } #posts { h3 { a { color: @darkTextColor; &:hover { color: darken(@darkTextColor, 10%); } } } h3, h4 { a { color: @darkTextColor; &:hover { color: darken(@darkTextColor, 10%); } } } a.action, a { color: @darkLinkColor; &:hover { color: darken(@darkLinkColor, 10%); } } } .modal { border-color: @darkNavBorder; background: @darkNavBG; input { color: #fff; } .form-hint { color: #ccc; } a:link, a:visited { color: lighten(@primary, 8%); } } } } body#pad { .pad-theme-transition; textarea, #title { .pad-theme-transition; } &.dark { textarea, #title, #editor { background-color: @darkBG; color: @darkTextColor; } } &.light { textarea, #title, #editor { background-color: @lightBG; color: @lightTextColor; } } } body { &.dark { nav#top-nav { a { color: @darkLinkColor; } } } } + +html { + &.light { + body:not(#pad):not(#pad-sub) { + background-color: @lightBG; + color: @lightTextColor; + } + } + + &.dark { + body:not(#pad):not(#pad-sub) { + background-color: @darkBG; + color: @darkTextColor; + } + + body:not(#pad):not(#pad-sub) { + a { + color: @darkLinkColor; + &:hover { + color: darken(@darkLinkColor, 10%); + } + } + + h1, h2, h3, h4, h5, h6 { + color: @darkTextColor; + a { + color: @darkTextColor; + } + } + + hr { + background: @darkNavBorder; + } + + footer nav, + .description, + .meta-note, + .subtitle, + .post-title time, + .post-title time a:link, + .post-title time a:visited, + .post-title + .time { + color: #999; + } + + input, textarea, select { + background: @darkNavBG; + color: @darkTextColor; + border-color: @darkNavBorder; + } + + pre, code, blockquote { + background-color: #262626; + color: @darkTextColor; + border-color: @darkNavBorder; + } + + .dropdown-nav ul ul, + nav#manage ul ul { + background: @darkNavBG; + border-color: @darkNavBorder; + } + + .dropdown-nav ul li, + nav#manage ul li { + &:hover { + background: @darkNavHoverBG; + } + &.current-user { + color: #fff; + } + &.menu-heading { + color: #ccc; + } + &.selected { + a { + color: #777; + } + } + } + + .dropdown-nav ul a, + nav#manage ul a, + header nav a, + #user-nav a, + #full-nav a { + color: @darkTextColor; + } + + nav#full-nav a.simple-btn { + background: @darkNavBG; + color: @darkTextColor; + border-color: @darkNavBorder !important; + } + + img.ic-18dp, + img.ic-24dp { + filter: brightness(1.15); + } + + .alert { + &.info { + color: #b9def0; + background-color: #24404d; + border-color: #35596a; + } + &.success { + color: #cde9c7; + background-color: #294232; + border-color: #3a6047; + } + &.danger { + color: #f4d999; + background-color: #473c1d; + border-color: #856404; + h3 { + color: @darkTextColor !important; + } + } + } + } + } +} + +.global-theme-toggle { + display: inline-block; + position: relative; + top: -0.15rem; + margin-right: 0.85rem; + padding: 0; + background: transparent; + border: 0; + box-shadow: none; + line-height: 1; + vertical-align: middle; + &:hover { + text-decoration: none; + } + img { + display: block; + filter: none !important; + } +} + +.global-theme-toggle--floating { + position: fixed; + top: 1.15rem; + right: 1.25rem; + z-index: 1000; + margin-left: 0; +} diff --git a/static/js/theme.js b/static/js/theme.js new file mode 100644 index 0000000..27a4566 --- /dev/null +++ b/static/js/theme.js @@ -0,0 +1,93 @@ +(function () { + var STORAGE_KEY = "padTheme"; + var LIGHT = "light"; + var DARK = "dark"; + + function preferredTheme() { + return window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? DARK : LIGHT; + } + + function storedTheme() { + try { + return localStorage.getItem(STORAGE_KEY); + } catch (e) { + return null; + } + } + + function currentTheme() { + return storedTheme() || preferredTheme(); + } + + function setTheme(theme) { + var next = theme === DARK ? DARK : LIGHT; + document.documentElement.classList.remove(LIGHT, DARK); + document.documentElement.classList.add(next); + if (document.body) { + document.body.classList.remove(LIGHT, DARK); + document.body.classList.add(next); + } + try { + localStorage.setItem(STORAGE_KEY, next); + } catch (e) { + // ignore storage errors + } + updateThemeIcons(next); + } + + function toggleTheme() { + setTheme(document.documentElement.classList.contains(DARK) ? LIGHT : DARK); + } + + function updateThemeIcons(theme) { + var btns = document.querySelectorAll('#tools a img, [data-theme-toggle] img'); + for (var i = 0; i < btns.length; i++) { + var img = btns[i]; + if (!img.src) { + continue; + } + if (/ic_brightness(_dark)?@2x\.png$/.test(img.src)) { + img.src = theme === LIGHT + ? img.src.replace(/ic_brightness(_dark)?@2x\.png$/, 'ic_brightness_dark@2x.png') + : img.src.replace(/ic_brightness(_dark)?@2x\.png$/, 'ic_brightness@2x.png'); + continue; + } + if (theme === LIGHT) { + if (!/_dark@2x\.png$/.test(img.src)) { + img.src = img.src.replace(/@2x\.png$/, '_dark@2x.png'); + } + } else { + img.src = img.src.replace(/_dark@2x\.png$/, '@2x.png'); + } + } + } + + function bindToggle(el) { + if (!el || el.dataset.themeBound === "true") { + return; + } + el.dataset.themeBound = "true"; + el.addEventListener("click", function (e) { + e.preventDefault(); + toggleTheme(); + }); + } + + function init() { + setTheme(currentTheme()); + bindToggle(document.getElementById("toggle-theme")); + var more = document.querySelectorAll("[data-theme-toggle]"); + for (var i = 0; i < more.length; i++) { + bindToggle(more[i]); + } + } + + window.toggleTheme = toggleTheme; + window.setTheme = setTheme; + + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", init); + } else { + init(); + } +})(); diff --git a/templates/base.tmpl b/templates/base.tmpl index 4440860..4944563 100644 --- a/templates/base.tmpl +++ b/templates/base.tmpl @@ -1,95 +1,106 @@ {{define "base"}} - + {{ template "head" . }} + {{if .CustomCSS}}{{end}}
{{ if .Chorus }} {{end}}
{{ template "content" . }}
{{ template "footer" . }} {{if not .JSDisabled}} + {{else}} {{if .WebFonts}}{{end}} {{end}} {{end}} {{define "body-attrs"}}{{end}} diff --git a/templates/chorus-collection-post.tmpl b/templates/chorus-collection-post.tmpl index 468455c..406b767 100644 --- a/templates/chorus-collection-post.tmpl +++ b/templates/chorus-collection-post.tmpl @@ -1,155 +1,167 @@ {{define "post"}} - + + {{.PlainDisplayTitle}} {{localhtml "title dash" .Language.String}} {{.Collection.DisplayTitle}} {{if .CustomCSS}}{{end}} {{if gt .Views 1}} {{end}} {{if gt (len .Images) 0}}{{else}}{{end}} {{range .Images}}{{else}}{{end}} {{template "collection-meta" .}} {{if .Collection.StyleSheet}}{{end}} {{if .Collection.RenderMathJax}} {{template "mathjax" . }} {{end}} {{template "highlighting" .}}
{{template "user-navigation" .}} {{if .Silenced}} {{template "user-silenced"}} {{end}}
{{if .IsScheduled}}

Scheduled

{{end}}{{if .Title.String}}

{{.FormattedDisplayTitle}}

{{end}}{{if and $.Collection.Format.ShowDates (not .IsPinned)}}{{end}}
{{.HTMLContent}}
{{ if .Collection.ShowFooterBranding }} {{ end }} {{if .Collection.CanShowScript}} {{range .Collection.ExternalScripts}}{{end}} {{if .Collection.Script}}{{end}} {{end}} + + {{if and .Monetization (not .IsOwner)}} {{end}} {{end}} diff --git a/templates/chorus-collection.tmpl b/templates/chorus-collection.tmpl index 742c544..8bc9a0b 100644 --- a/templates/chorus-collection.tmpl +++ b/templates/chorus-collection.tmpl @@ -1,236 +1,248 @@ {{define "collection"}} - + + {{.DisplayTitle}}{{if not .SingleUser}} — {{.SiteName}}{{end}} {{if .CustomCSS}}{{end}} {{if gt .CurrentPage 1}}{{end}} {{if lt .CurrentPage .TotalPages}}{{end}} {{if not .IsPrivate}}{{end}} {{template "collection-meta" .}} {{if .StyleSheet}}{{end}} {{if .RenderMathJax}} {{template "mathjax" .}} {{end}} {{template "highlighting" . }} {{template "user-navigation" .}} {{if .Silenced}} {{template "user-silenced"}} {{end}}

{{.DisplayTitle}}

{{if .Description}}

{{.Description}}

{{end}} {{/*if not .Public/*}} {{/*end*/}} {{if .PinnedPosts}} {{end}}
{{if .Posts}}
{{else}}
{{end}} {{if .IsWelcome}}

Welcome, {{.Username}}!

This is your new blog.

Start writing, or customize your blog.

Check out our writing guide to see what else you can do, and get in touch anytime with questions or feedback.

{{end}} {{template "posts" .}} {{if gt .TotalPages 1}}{{end}} {{if .Posts}}
{{else}}{{end}} {{if .ShowFooterBranding }} {{ end }} {{if .CanShowScript}} {{range .ExternalScripts}}{{end}} {{if .Script}}{{end}} {{end}} + + {{end}} diff --git a/templates/collection-archive.tmpl b/templates/collection-archive.tmpl index 5256c58..370a31c 100644 --- a/templates/collection-archive.tmpl +++ b/templates/collection-archive.tmpl @@ -1,118 +1,130 @@ {{define "collection"}} - + + Archive — {{.Collection.DisplayTitle}} {{if .CustomCSS}}{{end}} {{if gt .CurrentPage 1}}{{end}} {{if lt .CurrentPage .TotalPages}}{{end}} {{if not .IsPrivate}}{{end}} {{template "collection-meta" .}} {{if .StyleSheet}}{{end}}

{{.Collection.DisplayTitle}}

{{if .Posts -}}
{{- else -}}
{{- end}}

Archive

{{if .Flash}}

{{.Flash}}

{{end}} {{template "paging" .}} {{if .Posts}}
{{else}}{{end}} {{if .ShowFooterBranding }} {{ end }} + {{if .CanShowScript}} {{range .ExternalScripts}}{{end}} {{if .Collection.Script}}{{end}} {{end}} + {{end}} diff --git a/templates/collection-post.tmpl b/templates/collection-post.tmpl index 3d3132d..ec3d187 100644 --- a/templates/collection-post.tmpl +++ b/templates/collection-post.tmpl @@ -1,146 +1,158 @@ {{define "post"}} - + + {{.PlainDisplayTitle}} {{localhtml "title dash" .Language.String}} {{.Collection.DisplayTitle}} {{if .CustomCSS}}{{end}} {{ if .IsFound }} {{if gt .Views 1}} {{end}} {{if gt (len .Images) 0}}{{else}}{{end}} {{range .Images}}{{else}}{{end}} {{ end }} {{template "collection-meta" .}} {{if .Collection.StyleSheet}}{{end}} {{if .Collection.RenderMathJax}} {{template "mathjax" . }} {{end}} {{template "highlighting" .}}

{{if .Silenced}} {{template "user-silenced"}} {{end}}
{{if .IsScheduled}}

Scheduled

{{end}}{{if .Title.String}}

{{.FormattedDisplayTitle}}

{{end}}{{if and $.Collection.Format.ShowDates (not .IsPinned) .IsFound}}{{end}}
{{.HTMLContent}}
{{ if .Collection.ShowFooterBranding }} {{ end }} {{if .Collection.CanShowScript}} {{range .Collection.ExternalScripts}}{{end}} {{if .Collection.Script}}{{end}} {{end}} + + {{if and .Monetization (not .IsOwner)}} {{end}} {{end}} diff --git a/templates/collection-tags.tmpl b/templates/collection-tags.tmpl index c8e8a12..0200d60 100644 --- a/templates/collection-tags.tmpl +++ b/templates/collection-tags.tmpl @@ -1,211 +1,223 @@ {{define "collection-tags"}} - + + {{.Tag}} — {{.Collection.DisplayTitle}} {{if .CustomCSS}}{{end}} {{if not .Collection.IsPrivate}}{{end}} {{if gt .Views 1}} {{end}} {{template "collection-meta" .}} {{if .Collection.StyleSheet}}{{end}} {{if .Collection.RenderMathJax}} {{template "mathjax" .}} {{end}} {{template "highlighting" . }}

{{.Collection.DisplayTitle}}

{{if .Silenced}} {{template "user-silenced"}} {{end}} {{if .Posts}}
{{else}}
{{end}}

{{.Tag}}

{{template "posts" .}} {{if gt .TotalPages 1}}{{end}} {{if .Posts}}
{{else}}{{end}} {{ if .Collection.ShowFooterBranding }} {{ end }} {{if .CanShowScript}} {{range .ExternalScripts}}{{end}} {{if .Collection.Script}}{{end}} {{end}} {{if .IsOwner}} {{end}} + + {{end}} diff --git a/templates/collection.tmpl b/templates/collection.tmpl index 269004e..88d7dba 100644 --- a/templates/collection.tmpl +++ b/templates/collection.tmpl @@ -1,261 +1,273 @@ {{define "collection"}} - + + {{.DisplayTitle}}{{if not .SingleUser}} — {{.SiteName}}{{end}} {{if .CustomCSS}}{{end}} {{if gt .CurrentPage 1}}{{end}} {{if lt .CurrentPage .TotalPages}}{{end}} {{if not .IsPrivate}}{{end}} {{template "collection-meta" .}} {{if .StyleSheet}}{{end}} {{if .RenderMathJax}} {{template "mathjax" .}} {{end}} {{template "highlighting" . }} {{if or .IsOwner .SingleUser}} {{else if .IsCollLoggedIn}} {{end}}
{{if .Silenced}} {{template "user-silenced"}} {{end}}

{{if .Posts}}{{else}}write.as {{end}}{{.DisplayTitle}}

{{if .Description}}

{{.DisplayDescription}}

{{end}} {{/*if not .Public/*}} {{/*end*/}} {{if .PinnedPosts}} {{end}}
{{if .Posts}}
{{else}}
{{end}} {{if .IsWelcome}}

Welcome, {{.Username}}!

This is your new blog.

Start writing, or customize your blog.

Check out our writing guide to see what else you can do, and get in touch anytime with questions or feedback.

{{end}} {{if .Flash}}

{{.Flash}}

{{end}} {{template "posts" .}} {{if gt .TotalPages 1}}{{end}} {{if not .IsWelcome}}{{template "emailsubscribe" .}}{{end}} {{if .Posts}}
{{else}}{{end}} {{if .ShowFooterBranding }} {{ end }} {{if .CanShowScript}} {{range .ExternalScripts}}{{end}} {{if .Script}}{{end}} {{end}} + + {{end}} diff --git a/templates/edit-meta.tmpl b/templates/edit-meta.tmpl index 6c964b6..faddffd 100644 --- a/templates/edit-meta.tmpl +++ b/templates/edit-meta.tmpl @@ -1,379 +1,389 @@ {{define "edit-meta"}} Edit metadata: {{if .Post.Title}}{{.Post.Title}}{{else}}{{.Post.Id}}{{end}} — {{.SiteName}} {{if .CustomCSS}}{{end}}

Edit metadata: {{if .Post.Title}}{{.Post.Title}}{{else}}{{.Post.Id}}{{end}} view post

{{if .Flashes}}{{end}}
{{if .EditCollection}}
{{end}}
UTC now

Date format should be: YYYY-MM-DD HH:MM:SS

 
{{end}} diff --git a/templates/include/footer.tmpl b/templates/include/footer.tmpl index 8e3dec9..8c4e73b 100644 --- a/templates/include/footer.tmpl +++ b/templates/include/footer.tmpl @@ -1,46 +1,47 @@ {{define "footer"}}
{{if or .SingleUser .WFModesty}} {{else}}

{{.SiteName}}

{{end}} + {{end}} diff --git a/templates/password-collection.tmpl b/templates/password-collection.tmpl index fde4edc..0aade95 100644 --- a/templates/password-collection.tmpl +++ b/templates/password-collection.tmpl @@ -1,88 +1,100 @@ {{define "password-collection"}} - + + {{.DisplayTitle}}{{if not .SingleUser}} — {{.SiteName}}{{end}} {{if .CustomCSS}}{{end}} {{if .StyleSheet}}{{end}} {{if .SingleUser}} {{end}}

{{.DisplayTitle}}

{{if .Flashes}}
    {{range .Flashes}}
  • {{.}}
  • {{end}}
{{else}}

This blog requires a password.

{{end}}

{{if and .Script .CanShowScript}}{{end}} + + {{end}} diff --git a/templates/post.tmpl b/templates/post.tmpl index ca1c1f9..334333b 100644 --- a/templates/post.tmpl +++ b/templates/post.tmpl @@ -1,102 +1,114 @@ {{define "post"}} - + + {{if .Title}}{{.Title}}{{else}}{{.GenTitle}}{{end}} {{localhtml "title dash" .Language}} {{.SiteName}} {{if .IsCode}} {{end}} {{if .CustomCSS}}{{end}} {{if gt .Views 1}} {{end}} {{if gt (len .Images) 0}}{{else}}{{end}} {{range .Images}}{{else}}{{end}} {{if .Author}}{{end}} {{template "highlighting" .}}

{{.SiteName}}

{{if .Silenced}} {{template "user-silenced"}} {{end}}
{{if .Title}}

{{.Title}}

{{end}}{{ if .IsPlainText }}

{{.Content}}

{{ else }}
{{.HTMLContent}}
{{ end }}
{{if .IsCode}} {{else}} {{if .IsPlainText}}{{end}} {{end}} + + {{end}} diff --git a/templates/user/include/footer.tmpl b/templates/user/include/footer.tmpl index 94bb182..5073ffd 100644 --- a/templates/user/include/footer.tmpl +++ b/templates/user/include/footer.tmpl @@ -1,42 +1,42 @@ {{define "footer"}} {{template "foot" .}} {{template "body-end" .}} {{end}} {{define "foot"}} - + {{end}} {{define "body-end"}} {{end}} diff --git a/templates/user/include/header.tmpl b/templates/user/include/header.tmpl index ff57568..0ef95cb 100644 --- a/templates/user/include/header.tmpl +++ b/templates/user/include/header.tmpl @@ -1,117 +1,129 @@ {{define "user-navigation"}}
{{end}} {{define "header"}} - + {{.PageTitle}} {{if .Separator}}{{.Separator}}{{else}}—{{end}} {{.SiteName}} + {{if .CustomCSS}}{{end}} {{template "user-navigation" .}}
{{end}} {{define "admin-header"}}

Admin

{{end}}