Seasons: holidays through the year #46
No files matched your search
@@ -0,0 +1,51 @@
|
||||
# Seasons
|
||||
|
||||
`seasons:` in site.yaml dresses a site for holidays through the year. Each
|
||||
visitor's browser works out the day from its own date every time a page
|
||||
loads, so nothing is scheduled and nothing is rebuilt when a holiday starts
|
||||
or ends. The user guide is on hotdogcms.org (Writing › Holidays); this page
|
||||
is how it's put together.
|
||||
|
||||
```yaml
|
||||
seasons: true # or:
|
||||
seasons:
|
||||
anchor: header.top # the strip hangs under this; default the window's top
|
||||
logo: .brand-logo # the day's prop is laid over this
|
||||
art: # or swap a picture for your own drawings
|
||||
- { image: logo.svg, art: /img/season/logo-{prop}.svg }
|
||||
skip: footer # pictures in here keep their usual look
|
||||
only: [advent, pride] # or except: [halloween]
|
||||
greetings: false # no greeting on the strip
|
||||
```
|
||||
|
||||
`{{ seasons }}` in the head writes the tags (the starter has it). With
|
||||
seasons off it writes nothing and no file is added.
|
||||
|
||||
## The pieces
|
||||
|
||||
- `internal/seasons/src/core.js`: the dates. Holidays (`HOLIDAYS`, one strip
|
||||
and prop each; the first that matches dresses the page, all are greeted)
|
||||
and December's observances (`SCENES`, drawn side by side at the end of the
|
||||
strip). Lunar dates come from the browser's `Intl` calendars (Chinese,
|
||||
Hebrew, Islamic, Persian); where a browser lacks one, those holidays don't
|
||||
show. Easter is computed (Western and Orthodox), Holi and Diwali from the
|
||||
moon's phases, Dongzhi from the solstice. Advent alone runs on UTC.
|
||||
- `src/render.js`: the strips and scenes, drawn as SVG in the page.
|
||||
- `src/run.js`: places the strip, swaps pictures, lays props, handles
|
||||
`?season=`.
|
||||
- `src/season.css`: the strip's look. The build links it, and adds where each
|
||||
kind of prop sits on a logo (`.season-prop-head`, `-eyes`, `-ear`, `-pin`,
|
||||
`-side`), which a site can restyle.
|
||||
- `props/*.svg`: each prop on its own, fingerprinted into
|
||||
`hotdog-seasons/<prop>.<hash>.svg`.
|
||||
|
||||
The build checks `only:` and `except:` against the holiday names, and that a
|
||||
site's own `art:` has a drawing for every prop (`static/` plus the address,
|
||||
with `{prop}` filled in).
|
||||
|
||||
## Previewing
|
||||
|
||||
`?season=<id>` shows one holiday, `?season=YYYY-MM-DD` everything that date
|
||||
shows, `?season=off` nothing and `?season=auto` today again; each lasts for
|
||||
the browser tab's session. `TZ=UTC node internal/seasons/src/dates-test.js
|
||||
2026 2027` lists every holiday's days for those years.
|
||||
@@ -275,6 +275,9 @@ func prepareWith(siteDir string, s *site.Site, out string, formOverrides map[str
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := addSeasons(siteDir, s.Config, assets, out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.Config.Analytics != nil {
|
||||
if err := assets.add(out, "hotdog-consent.js", consentScript); err != nil {
|
||||
return nil, err
|
||||
@@ -310,6 +313,7 @@ func prepareWith(siteDir string, s *site.Site, out string, formOverrides map[str
|
||||
}
|
||||
fm["consent"] = func() template.HTML { return consentTags(s.Config, assets) }
|
||||
fm["cart"] = func() template.HTML { return cartTags(s.Config, assets) }
|
||||
fm["seasons"] = func() (template.HTML, error) { return seasonsTags(s.Config, assets) }
|
||||
fm["cartLink"] = func() template.HTML { return cartLink(s.Config) }
|
||||
fm["cartOn"] = func() bool { return s.Config.Cart.On() }
|
||||
fm["variantPicker"] = func() template.HTML { return variantPicker(assets) }
|
||||
|
||||
@@ -522,3 +522,48 @@ func TestMarkdownOutputs(t *testing.T) {
|
||||
t.Error("a generated tag page got a Markdown copy")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeasons(t *testing.T) {
|
||||
dir := writeStarter(t)
|
||||
res, err := Run(Options{SiteDir: dir})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
home, _ := os.ReadFile(filepath.Join(res.Out, "index.html"))
|
||||
if strings.Contains(string(home), "hotdog-seasons") {
|
||||
t.Error("seasons are on without seasons: in site.yaml")
|
||||
}
|
||||
|
||||
cfg, _ := os.ReadFile(filepath.Join(dir, "site.yaml"))
|
||||
os.WriteFile(filepath.Join(dir, "site.yaml"), append(cfg, []byte("seasons:\n logo: .brand-logo\n except: [halloween]\n")...), 0o644)
|
||||
if res, err = Run(Options{SiteDir: dir}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
home, _ = os.ReadFile(filepath.Join(res.Out, "index.html"))
|
||||
m := regexp.MustCompile(`<script src="(/hotdog-seasons\.[0-9a-f]{10}\.js)" defer data-seasons="([^"]*)"></script>`).FindStringSubmatch(string(home))
|
||||
if m == nil || !regexp.MustCompile(`<link rel="stylesheet" href="/hotdog-seasons\.[0-9a-f]{10}\.css">`).MatchString(string(home)) {
|
||||
t.Fatalf("home page has no seasons tags:\n%s", home)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(res.Out, m[1])); err != nil {
|
||||
t.Error("script not written")
|
||||
}
|
||||
props, _ := filepath.Glob(filepath.Join(res.Out, "hotdog-seasons", "santa.*.svg"))
|
||||
if len(props) != 1 || !strings.Contains(m[2], "/hotdog-seasons/santa.") {
|
||||
t.Errorf("santa prop: %v, %s", props, m[2])
|
||||
}
|
||||
|
||||
// A holiday that doesn't exist, and art with drawings missing, stop the
|
||||
// build and say why.
|
||||
os.WriteFile(filepath.Join(dir, "site.yaml"), append(cfg, []byte("seasons:\n only: [arbor]\n")...), 0o644)
|
||||
if _, err := Run(Options{SiteDir: dir}); err == nil || !strings.Contains(err.Error(), `no holiday called "arbor"`) {
|
||||
t.Errorf("unknown holiday: %v", err)
|
||||
}
|
||||
os.WriteFile(filepath.Join(dir, "site.yaml"), append(cfg, []byte("seasons:\n art:\n - image: logo.svg\n art: /img/logo-{prop}.svg\n")...), 0o644)
|
||||
if _, err := Run(Options{SiteDir: dir}); err == nil || !strings.Contains(err.Error(), "missing 17 of 17 drawings") {
|
||||
t.Errorf("missing art: %v", err)
|
||||
}
|
||||
os.WriteFile(filepath.Join(dir, "site.yaml"), append(cfg, []byte("seasons:\n art:\n - image: logo.svg\n art: img/logo.svg\n")...), 0o644)
|
||||
if _, err := Run(Options{SiteDir: dir}); err == nil || !strings.Contains(err.Error(), "with {prop}") {
|
||||
t.Errorf("bad art address: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.coffeylabs.org/coffey-labs/hotdog-cms/internal/seasons"
|
||||
"git.coffeylabs.org/coffey-labs/hotdog-cms/internal/site"
|
||||
)
|
||||
|
||||
// addSeasons checks site.yaml's seasons: block and writes the script, its
|
||||
// stylesheet and the props, when seasons are on.
|
||||
func addSeasons(siteDir string, cfg *site.Config, a *Assets, out string) error {
|
||||
c := cfg.Seasons
|
||||
if !c.On() {
|
||||
return nil
|
||||
}
|
||||
for _, list := range [][]string{c.Only, c.Except} {
|
||||
for _, id := range list {
|
||||
if !seasons.Known(id) {
|
||||
return fmt.Errorf("site.yaml: seasons: no holiday called %q (they are: %s)", id, strings.Join(seasons.IDs, ", "))
|
||||
}
|
||||
}
|
||||
}
|
||||
// A site's own art needs a drawing for every prop it might show.
|
||||
for _, art := range c.Art {
|
||||
var missing []string
|
||||
for _, p := range seasons.PropNames() {
|
||||
rel := strings.ReplaceAll(strings.TrimPrefix(art.Art, "/"), "{prop}", p)
|
||||
if _, err := os.Stat(filepath.Join(siteDir, "static", filepath.FromSlash(rel))); err != nil {
|
||||
missing = append(missing, "static/"+rel)
|
||||
}
|
||||
}
|
||||
if len(missing) > 0 {
|
||||
return fmt.Errorf("site.yaml: seasons: art for %q is missing %d of %d drawings: %s", art.Image, len(missing), len(seasons.Props), strings.Join(missing, ", "))
|
||||
}
|
||||
}
|
||||
if out != "" {
|
||||
if err := os.MkdirAll(filepath.Join(out, "hotdog-seasons"), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := a.add(out, "hotdog-seasons.js", seasons.Script); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.add(out, "hotdog-seasons.css", seasons.Style); err != nil {
|
||||
return err
|
||||
}
|
||||
for name, svg := range seasons.Props {
|
||||
if err := a.add(out, "hotdog-seasons/"+name+".svg", svg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// seasonsTags is {{ seasons }}: the stylesheet and script tags, or nothing
|
||||
// when seasons are off.
|
||||
func seasonsTags(cfg *site.Config, a *Assets) (template.HTML, error) {
|
||||
c := cfg.Seasons
|
||||
if !c.On() {
|
||||
return "", nil
|
||||
}
|
||||
o := seasons.Options{Anchor: c.Anchor, Logo: c.Logo, Skip: c.Skip, Only: c.Only, Except: c.Except,
|
||||
Greetings: c.Greetings == nil || *c.Greetings, PropURLs: map[string]string{}}
|
||||
o.ScriptURL, _ = a.URL("hotdog-seasons.js")
|
||||
o.CSSURL, _ = a.URL("hotdog-seasons.css")
|
||||
for name := range seasons.Props {
|
||||
o.PropURLs[name], _ = a.URL("hotdog-seasons/" + name + ".svg")
|
||||
}
|
||||
for _, art := range c.Art {
|
||||
o.Art = append(o.Art, [2]string{art.Image, strings.ReplaceAll(art.Art, "{prop}", "{p}")})
|
||||
}
|
||||
return seasons.Tags(o)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-62 -56 140 68"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><defs><clipPath id="season-bd"><path d="M-26 0 L4 -46 L26 0 Z"/></clipPath></defs>
|
||||
<path d="M-26 0 L4 -46 L26 0 Z" fill="#3BA3F0"/>
|
||||
<g clip-path="url(#season-bd)" stroke="none"><path d="M-40 -6 L40 -26 L40 -18 L-40 2 Z M-40 -24 L40 -44 L40 -36 L-40 -16 Z" fill="#FFD23F"/></g>
|
||||
<path d="M-26 0 L4 -46 L26 0 Z" fill="none"/>
|
||||
<circle cx="4" cy="-48" r="8" fill="#FF5FA2"/>
|
||||
<polygon points="-38.0,-36.0 -36.4,-31.6 -32.0,-30.0 -36.4,-28.4 -38.0,-24.0 -39.6,-28.4 -44.0,-30.0 -39.6,-31.6" fill="#FFD23F" stroke="none"/><polygon points="36.0,-41.0 37.3,-37.3 41.0,-36.0 37.3,-34.7 36.0,-31.0 34.7,-34.7 31.0,-36.0 34.7,-37.3" fill="#FF5FA2" stroke="none"/></g></svg>
|
||||
|
After Width: | Height: | Size: 830 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-62 -56 140 68"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><path d="M-48 4 Q0 -16 48 4" fill="none" stroke="#F7A8C4" stroke-width="15.60"/>
|
||||
<g transform="rotate(-16 -20 -4)"><ellipse cx="-20" cy="-28" rx="11" ry="25" fill="#FFFFFF"/><ellipse cx="-20" cy="-26" rx="5" ry="17" fill="#F7A8C4" stroke="none"/></g>
|
||||
<g transform="rotate(24 20 -4)"><path d="M10 -4 C6 -26 12 -44 22 -46 C34 -48 40 -36 36 -24 C42 -28 50 -24 50 -18 C40 -14 32 -10 30 -4 Z" fill="#FFFFFF"/>
|
||||
<path d="M17 -6 C15 -24 18 -38 23 -40 C28 -40 31 -32 28 -20 Z" fill="#F7A8C4" stroke="none"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 674 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-62 -56 140 68"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><path d="M-42 0 L-46 -38 L-23 -18 L0 -44 L23 -18 L46 -38 L42 0 Z" fill="#F2C230"/>
|
||||
<path d="M-43 -12 L43 -12 L42 0 L-42 0 Z" fill="#D9A21B"/>
|
||||
<circle cx="-46" cy="-40" r="5" fill="#F2C230"/><circle cx="0" cy="-46" r="5" fill="#F2C230"/><circle cx="46" cy="-40" r="5" fill="#F2C230"/>
|
||||
<circle cx="0" cy="-6" r="5.5" fill="#D62839"/><circle cx="-24" cy="-6" r="4.5" fill="#2D7DD2"/><circle cx="24" cy="-6" r="4.5" fill="#2BA84A"/></g></svg>
|
||||
|
After Width: | Height: | Size: 600 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-62 -56 140 68"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><path d="M-50 2 Q0 -26 50 2" fill="none" stroke="#3B7D2C" stroke-width="9.60"/><ellipse cx="-46" cy="0" rx="9" ry="4.5" transform="rotate(30 -46 0)" fill="#4E9A3A" stroke="none"/><ellipse cx="-30" cy="-10" rx="9" ry="4.5" transform="rotate(-20 -30 -10)" fill="#4E9A3A" stroke="none"/><ellipse cx="-10" cy="-14" rx="9" ry="4.5" transform="rotate(25 -10 -14)" fill="#4E9A3A" stroke="none"/><ellipse cx="10" cy="-14" rx="9" ry="4.5" transform="rotate(-25 10 -14)" fill="#4E9A3A" stroke="none"/><ellipse cx="30" cy="-10" rx="9" ry="4.5" transform="rotate(20 30 -10)" fill="#4E9A3A" stroke="none"/><ellipse cx="46" cy="0" rx="9" ry="4.5" transform="rotate(-30 46 0)" fill="#4E9A3A" stroke="none"/><g stroke="none"><ellipse cx="-29.3" cy="-5.0" rx="5.9" ry="5.9" fill="#FFFFFF"/><ellipse cx="-33.7" cy="2.5" rx="5.9" ry="5.9" fill="#FFFFFF"/><ellipse cx="-42.3" cy="2.5" rx="5.9" ry="5.9" fill="#FFFFFF"/><ellipse cx="-46.7" cy="-5.0" rx="5.9" ry="5.9" fill="#FFFFFF"/><ellipse cx="-42.3" cy="-12.5" rx="5.9" ry="5.9" fill="#FFFFFF"/><ellipse cx="-33.7" cy="-12.5" rx="5.9" ry="5.9" fill="#FFFFFF"/><circle cx="-38" cy="-5" r="5.0" fill="#FFC83D"/></g><g stroke="none"><ellipse cx="-11.6" cy="-12.0" rx="5.0" ry="5.0" fill="#6C8EF5"/><ellipse cx="-15.3" cy="-5.6" rx="5.0" ry="5.0" fill="#6C8EF5"/><ellipse cx="-22.7" cy="-5.6" rx="5.0" ry="5.0" fill="#6C8EF5"/><ellipse cx="-26.4" cy="-12.0" rx="5.0" ry="5.0" fill="#6C8EF5"/><ellipse cx="-22.7" cy="-18.4" rx="5.0" ry="5.0" fill="#6C8EF5"/><ellipse cx="-15.3" cy="-18.4" rx="5.0" ry="5.0" fill="#6C8EF5"/><circle cx="-19" cy="-12" r="4.3" fill="#FFE07A"/></g><g stroke="none"><ellipse cx="9.3" cy="-15.0" rx="6.3" ry="6.3" fill="#FFFFFF"/><ellipse cx="4.7" cy="-6.9" rx="6.3" ry="6.3" fill="#FFFFFF"/><ellipse cx="-4.6" cy="-6.9" rx="6.3" ry="6.3" fill="#FFFFFF"/><ellipse cx="-9.3" cy="-15.0" rx="6.3" ry="6.3" fill="#FFFFFF"/><ellipse cx="-4.7" cy="-23.1" rx="6.3" ry="6.3" fill="#FFFFFF"/><ellipse cx="4.7" cy="-23.1" rx="6.3" ry="6.3" fill="#FFFFFF"/><circle cx="0" cy="-15" r="5.4" fill="#FFC83D"/></g><g stroke="none"><ellipse cx="26.4" cy="-12.0" rx="5.0" ry="5.0" fill="#F28FB8"/><ellipse cx="22.7" cy="-5.6" rx="5.0" ry="5.0" fill="#F28FB8"/><ellipse cx="15.3" cy="-5.6" rx="5.0" ry="5.0" fill="#F28FB8"/><ellipse cx="11.6" cy="-12.0" rx="5.0" ry="5.0" fill="#F28FB8"/><ellipse cx="15.3" cy="-18.4" rx="5.0" ry="5.0" fill="#F28FB8"/><ellipse cx="22.7" cy="-18.4" rx="5.0" ry="5.0" fill="#F28FB8"/><circle cx="19" cy="-12" r="4.3" fill="#FFE07A"/></g><g stroke="none"><ellipse cx="46.7" cy="-5.0" rx="5.9" ry="5.9" fill="#FFE04A"/><ellipse cx="42.3" cy="2.5" rx="5.9" ry="5.9" fill="#FFE04A"/><ellipse cx="33.7" cy="2.5" rx="5.9" ry="5.9" fill="#FFE04A"/><ellipse cx="29.3" cy="-5.0" rx="5.9" ry="5.9" fill="#FFE04A"/><ellipse cx="33.7" cy="-12.5" rx="5.9" ry="5.9" fill="#FFE04A"/><ellipse cx="42.3" cy="-12.5" rx="5.9" ry="5.9" fill="#FFE04A"/><circle cx="38" cy="-5" r="5.0" fill="#E58A00"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-70 -54 154 96"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><rect x="-66" y="-6" width="132" height="10" rx="5" fill="#2D7DD2"/>
|
||||
<ellipse cx="-27" cy="-1" rx="22" ry="16" fill="#9BE3FF" fill-opacity="0.78" stroke="#FF8A2A" stroke-width="9.60"/>
|
||||
<ellipse cx="27" cy="-1" rx="22" ry="16" fill="#9BE3FF" fill-opacity="0.78" stroke="#FF8A2A" stroke-width="9.60"/>
|
||||
<path d="M-5 -2 Q0 -6 5 -2" fill="none" stroke="#FF8A2A" stroke-width="8.40"/>
|
||||
<path d="M-36 -8 L-30 -10 M18 -8 L24 -10" stroke="#FFFFFF" stroke-width="6.60"/>
|
||||
<g fill="#5CC8FF" stroke="none"><path d="M-58 22 q4 7 0 10 q-4 -3 0 -10 Z"/><path d="M60 16 q4 7 0 10 q-4 -3 0 -10 Z"/><path d="M48 32 q3 5 0 7 q-3 -2 0 -7 Z"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 804 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-70 -54 154 96"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><g fill="#FF4FA3" fill-opacity="0.82" stroke="none"><circle cx="-40" cy="24" r="11"/><circle cx="-30.1" cy="18.5" r="5.0"/><circle cx="-48.8" cy="30.6" r="3.8"/><circle cx="-36.7" cy="36.1" r="2.8"/></g><g fill="#3BD16F" fill-opacity="0.82" stroke="none"><circle cx="40" cy="26" r="10"/><circle cx="49.0" cy="21.0" r="4.5"/><circle cx="32.0" cy="32.0" r="3.5"/><circle cx="43.0" cy="37.0" r="2.5"/></g><g fill="#FFC21A" fill-opacity="0.82" stroke="none"><circle cx="-6" cy="-30" r="7"/><circle cx="0.3" cy="-33.5" r="3.1"/><circle cx="-11.6" cy="-25.8" r="2.4"/><circle cx="-3.9" cy="-22.3" r="1.8"/></g><g fill="#8B5CFF" fill-opacity="0.82" stroke="none"><circle cx="22" cy="-26" r="5"/><circle cx="26.5" cy="-28.5" r="2.2"/><circle cx="18.0" cy="-23.0" r="1.8"/><circle cx="23.5" cy="-20.5" r="1.2"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 966 B |
@@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-54 -4 108 194"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><path d="M0 0 L0 18" fill="none"/>
|
||||
<rect x="-22" y="16" width="44" height="12" rx="3" fill="#F2C230"/>
|
||||
<ellipse cx="0" cy="78" rx="50" ry="52" fill="#D62839"/>
|
||||
<ellipse cx="0" cy="78" rx="26" ry="52" fill="none" stroke="#A51C2C" stroke-width="7.20"/>
|
||||
<path d="M0 26 L0 130" stroke="#A51C2C" stroke-width="7.20"/>
|
||||
<rect x="-22" y="128" width="44" height="12" rx="3" fill="#F2C230"/>
|
||||
<path d="M-8 140 L-10 186 L10 186 L8 140 Z" fill="#D62839"/>
|
||||
<path d="M-4 144 L-5 182 M0 144 L0 184 M4 144 L5 182" stroke="#F2C230" stroke-width="3.60"/></g></svg>
|
||||
|
After Width: | Height: | Size: 723 B |
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-62 -56 140 68"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><path d="M-50 2 Q0 -18 50 2" fill="none" stroke="#2F6F2A" stroke-width="10.80"/><rect x="-39" y="-25.9" width="10" height="19.9" rx="2" fill="#FBFBF2" stroke-width="2.10"/>
|
||||
<path d="M-34 -35.9 c4 5 4 8 0 10 c-4 -2 -4 -5 0 -10 Z" fill="#FFCF3D" stroke="#E08A00" stroke-width="1.50"/><rect x="-22" y="-28.0" width="10" height="22.0" rx="2" fill="#FBFBF2" stroke-width="2.10"/>
|
||||
<path d="M-17 -38.0 c4 5 4 8 0 10 c-4 -2 -4 -5 0 -10 Z" fill="#FFCF3D" stroke="#E08A00" stroke-width="1.50"/><rect x="-5" y="-30.0" width="10" height="24.0" rx="2" fill="#FBFBF2" stroke-width="2.10"/>
|
||||
<path d="M0 -40.0 c4 5 4 8 0 10 c-4 -2 -4 -5 0 -10 Z" fill="#FFCF3D" stroke="#E08A00" stroke-width="1.50"/><rect x="12" y="-28.0" width="10" height="22.0" rx="2" fill="#FBFBF2" stroke-width="2.10"/>
|
||||
<path d="M17 -38.0 c4 5 4 8 0 10 c-4 -2 -4 -5 0 -10 Z" fill="#FFCF3D" stroke="#E08A00" stroke-width="1.50"/><rect x="29" y="-25.9" width="10" height="19.9" rx="2" fill="#FBFBF2" stroke-width="2.10"/>
|
||||
<path d="M34 -35.9 c4 5 4 8 0 10 c-4 -2 -4 -5 0 -10 Z" fill="#FFCF3D" stroke="#E08A00" stroke-width="1.50"/><ellipse cx="-44" cy="-2" rx="8" ry="4" transform="rotate(20 -44 -2)" fill="#3E8E3A" stroke="none"/><ellipse cx="-30" cy="-6" rx="8" ry="4" transform="rotate(-15 -30 -6)" fill="#3E8E3A" stroke="none"/><ellipse cx="-14" cy="-8" rx="8" ry="4" transform="rotate(15 -14 -8)" fill="#3E8E3A" stroke="none"/><ellipse cx="2" cy="-8" rx="8" ry="4" transform="rotate(-15 2 -8)" fill="#3E8E3A" stroke="none"/><ellipse cx="18" cy="-8" rx="8" ry="4" transform="rotate(15 18 -8)" fill="#3E8E3A" stroke="none"/><ellipse cx="32" cy="-6" rx="8" ry="4" transform="rotate(-15 32 -6)" fill="#3E8E3A" stroke="none"/><ellipse cx="46" cy="-2" rx="8" ry="4" transform="rotate(-20 46 -2)" fill="#3E8E3A" stroke="none"/><circle cx="-38" cy="-1" r="2.6" fill="#D62839" stroke="none"/><circle cx="-22" cy="-4" r="2.6" fill="#D62839" stroke="none"/><circle cx="-6" cy="-5" r="2.6" fill="#D62839" stroke="none"/><circle cx="10" cy="-5" r="2.6" fill="#D62839" stroke="none"/><circle cx="26" cy="-4" r="2.6" fill="#D62839" stroke="none"/><circle cx="40" cy="-1" r="2.6" fill="#D62839" stroke="none"/></g></svg>
|
||||
|
After Width: | Height: | Size: 2.3 KiB |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-56 -48 104 104"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><ellipse cx="-30" cy="30" rx="22" ry="9" transform="rotate(35 -30 30)" fill="#3E8E3A"/>
|
||||
<ellipse cx="30" cy="34" rx="20" ry="8" transform="rotate(-35 30 34)" fill="#3E8E3A"/>
|
||||
<circle cx="0" cy="0" r="44" fill="#E87A12"/>
|
||||
<g stroke="none"><circle cx="31.0" cy="0.0" r="15" fill="#F08A1C"/><circle cx="26.8" cy="15.5" r="15" fill="#F08A1C"/><circle cx="15.5" cy="26.8" r="15" fill="#F08A1C"/><circle cx="0.0" cy="31.0" r="15" fill="#F08A1C"/><circle cx="-15.5" cy="26.8" r="15" fill="#F08A1C"/><circle cx="-26.8" cy="15.5" r="15" fill="#F08A1C"/><circle cx="-31.0" cy="0.0" r="15" fill="#F08A1C"/><circle cx="-26.8" cy="-15.5" r="15" fill="#F08A1C"/><circle cx="-15.5" cy="-26.8" r="15" fill="#F08A1C"/><circle cx="-0.0" cy="-31.0" r="15" fill="#F08A1C"/><circle cx="15.5" cy="-26.8" r="15" fill="#F08A1C"/><circle cx="26.8" cy="-15.5" r="15" fill="#F08A1C"/><circle cx="19.0" cy="0.0" r="12" fill="#FFA726"/><circle cx="15.4" cy="11.2" r="12" fill="#FFA726"/><circle cx="5.9" cy="18.1" r="12" fill="#FFA726"/><circle cx="-5.9" cy="18.1" r="12" fill="#FFA726"/><circle cx="-15.4" cy="11.2" r="12" fill="#FFA726"/><circle cx="-19.0" cy="0.0" r="12" fill="#FFA726"/><circle cx="-15.4" cy="-11.2" r="12" fill="#FFA726"/><circle cx="-5.9" cy="-18.1" r="12" fill="#FFA726"/><circle cx="5.9" cy="-18.1" r="12" fill="#FFA726"/><circle cx="15.4" cy="-11.2" r="12" fill="#FFA726"/><circle cx="9.0" cy="0.0" r="9" fill="#FFB83F"/><circle cx="5.6" cy="7.0" r="9" fill="#FFB83F"/><circle cx="-2.0" cy="8.8" r="9" fill="#FFB83F"/><circle cx="-8.1" cy="3.9" r="9" fill="#FFB83F"/><circle cx="-8.1" cy="-3.9" r="9" fill="#FFB83F"/><circle cx="-2.0" cy="-8.8" r="9" fill="#FFB83F"/><circle cx="5.6" cy="-7.0" r="9" fill="#FFB83F"/><circle r="6" fill="#D96A00"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-70 -54 154 96"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><path fill-rule="evenodd" d="M-58 -6 C-52 -24 -20 -24 -6 -12 Q0 -8 6 -12 C20 -24 52 -24 58 -6 C60 12 40 22 24 18 C14 16 8 10 0 10 C-8 10 -14 16 -24 18 C-40 22 -60 12 -58 -6 Z
|
||||
M-42 -2 C-38 -10 -16 -10 -12 -2 C-16 6 -38 6 -42 -2 Z M42 -2 C38 -10 16 -10 12 -2 C16 6 38 6 42 -2 Z" fill="#7B3FB0"/>
|
||||
<path d="M52 -14 C56 -30 66 -44 80 -50 C76 -36 70 -24 58 -12 Z" fill="#2BB3A8"/>
|
||||
<path d="M54 -14 L74 -44" stroke="#F2C230" stroke-width="4.80"/>
|
||||
<g fill="#F2C230" stroke="none"><circle cx="0" cy="3" r="3"/><circle cx="-50" cy="6" r="2.4"/><circle cx="50" cy="6" r="2.4"/><circle cx="-30" cy="-16" r="2.2"/><circle cx="30" cy="-16" r="2.2"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 817 B |
@@ -0,0 +1,9 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-54 -4 108 194"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><defs><radialGradient id="season-ml" cx="0.45" cy="0.4" r="0.65"><stop offset="0" stop-color="#FFF1B0"/><stop offset="0.6" stop-color="#FFC94A"/><stop offset="1" stop-color="#FF9A1F"/></radialGradient></defs>
|
||||
<path d="M0 0 L0 20" fill="none"/>
|
||||
<rect x="-18" y="18" width="36" height="10" rx="3" fill="#C8521E"/>
|
||||
<circle cx="0" cy="76" r="50" fill="url(#season-ml)"/>
|
||||
<ellipse cx="0" cy="76" rx="24" ry="50" fill="none" stroke="#E9861A" stroke-width="5.40"/>
|
||||
<g fill="#FFFFFF" stroke="none"><ellipse cx="2" cy="88" rx="14" ry="11"/><circle cx="-10" cy="76" r="8"/>
|
||||
<ellipse cx="-14" cy="62" rx="3" ry="9" transform="rotate(-15 -14 62)"/><ellipse cx="-7" cy="61" rx="3" ry="9" transform="rotate(10 -7 61)"/><circle cx="16" cy="88" r="4"/></g>
|
||||
<rect x="-18" y="124" width="36" height="10" rx="3" fill="#C8521E"/>
|
||||
<path d="M-6 134 L-8 176 L8 176 L6 134 Z" fill="#E5412B"/></g></svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-56 -48 104 104"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><ellipse cx="26" cy="32" rx="22" ry="8" transform="rotate(-35 26 32)" fill="#2F7D32"/>
|
||||
<circle cx="-15" cy="-14" r="24" fill="#D62828"/><circle cx="15" cy="-14" r="24" fill="#D62828"/>
|
||||
<circle cx="-15" cy="14" r="24" fill="#C11F1F"/><circle cx="15" cy="14" r="24" fill="#C11F1F"/>
|
||||
<circle cx="0" cy="0" r="12" fill="#1B1B1B"/>
|
||||
<g fill="#3A3A3A" stroke="none"><circle cx="0" cy="0" r="3"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 569 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-56 -48 104 104"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><defs><clipPath id="season-pp"><circle r="44"/></clipPath></defs><g clip-path="url(#season-pp)"><rect x="-50" y="-44.00" width="100" height="14.97" fill="#E40303" stroke="none"/><rect x="-50" y="-29.33" width="100" height="14.97" fill="#FF8C00" stroke="none"/><rect x="-50" y="-14.67" width="100" height="14.97" fill="#FFED00" stroke="none"/><rect x="-50" y="0.00" width="100" height="14.97" fill="#008026" stroke="none"/><rect x="-50" y="14.67" width="100" height="14.97" fill="#24408E" stroke="none"/><rect x="-50" y="29.33" width="100" height="14.97" fill="#732982" stroke="none"/><path d="M-50.00 -44.00 L-50.00 -44.00 L-5.00 0.00 L-50.00 44.00 L-50.00 44.00 Z" fill="#000000" stroke="none"/><path d="M-50.00 -36.67 L-12.50 0.00 L-50.00 36.67 Z" fill="#613915" stroke="none"/><path d="M-50.00 -29.33 L-20.00 0.00 L-50.00 29.33 Z" fill="#5BCEFA" stroke="none"/><path d="M-50.00 -22.00 L-27.50 0.00 L-50.00 22.00 Z" fill="#F5A9B8" stroke="none"/><path d="M-50.00 -14.67 L-35.00 0.00 L-50.00 14.67 Z" fill="#FFFFFF" stroke="none"/></g><circle r="44" fill="none"/><path d="M-26 -30 a36 36 0 0 1 30 -10" stroke="#FFFFFF" stroke-opacity="0.7" stroke-width="5.40" fill="none"/></g></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-62 -56 140 68"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><path d="M-40 0 C-36 -26 -14 -44 14 -46 C42 -48 62 -32 66 -10 C56 -22 44 -24 36 -16 C31 -10 33 -4 38 0 Z" fill="#D62839"/>
|
||||
<path d="M18 -44 C42 -44 58 -30 62 -14 C54 -22 44 -24 36 -16 C31 -10 33 -4 38 0 L20 0 C17 -16 20 -32 18 -44 Z" fill="#A51C2C" stroke="none"/>
|
||||
<path d="M-40 0 C-36 -26 -14 -44 14 -46 C42 -48 62 -32 66 -10 C56 -22 44 -24 36 -16 C31 -10 33 -4 38 0" fill="none"/>
|
||||
<rect x="-52" y="-9" width="104" height="20" rx="10" fill="#FFFFFF"/>
|
||||
<path d="M-40 6 h12 M-14 7 h10 M12 6 h12 M34 7 h8" stroke="#E4ECF2" stroke-width="4.80" fill="none"/>
|
||||
<circle cx="66" cy="-6" r="12" fill="#FFFFFF"/>
|
||||
<path d="M60 -2 a7 7 0 0 0 10 3" stroke="#E4ECF2" stroke-width="4.80" fill="none"/></g></svg>
|
||||
|
After Width: | Height: | Size: 870 B |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-70 -54 154 96"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><path d="M-52 -6 L-64 -9 M52 -6 L64 -9" fill="none"/>
|
||||
<path d="M-6 -4 Q0 -10 6 -4" fill="none"/>
|
||||
<rect x="-52" y="-13" width="46" height="27" rx="8" fill="#17181D"/>
|
||||
<rect x="6" y="-13" width="46" height="27" rx="8" fill="#17181D"/>
|
||||
<path d="M-44 -6 L-36 -6 M14 -6 L22 -6" stroke="#8D93A6" stroke-width="6.60"/></g></svg>
|
||||
|
After Width: | Height: | Size: 487 B |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-62 -56 140 68"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><path d="M-30 -4 L-34 -48 Q0 -54 34 -48 L30 -4 Z" fill="#26232B"/>
|
||||
<path d="M-31 -20 L31 -20 L30.4 -9 L-30.4 -9 Z" fill="#F2C230"/>
|
||||
<ellipse cx="0" cy="-1" rx="52" ry="8" fill="#26232B"/>
|
||||
<path d="M-24 -44 Q-22 -30 -24 -24" stroke="#5A5566" stroke-width="5.40" fill="none"/>
|
||||
<polygon points="48.0,-49.0 50.4,-42.4 57.0,-40.0 50.4,-37.6 48.0,-31.0 45.6,-37.6 39.0,-40.0 45.6,-42.4" fill="#F2C230" stroke="none"/><polygon points="-50.0,-34.0 -48.4,-29.6 -44.0,-28.0 -48.4,-26.4 -50.0,-22.0 -51.6,-26.4 -56.0,-28.0 -51.6,-29.6" fill="#FF7AB6" stroke="none"/><polygon points="58.0,-21.0 59.3,-17.3 63.0,-16.0 59.3,-14.7 58.0,-11.0 56.7,-14.7 53.0,-16.0 56.7,-17.3" fill="#7FE3FF" stroke="none"/></g></svg>
|
||||
|
After Width: | Height: | Size: 867 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-62 -56 140 68"><g stroke="#140C02" stroke-width="6" stroke-linejoin="round" stroke-linecap="round"><ellipse cx="0" cy="-2" rx="56" ry="9" fill="#2E2238"/>
|
||||
<path d="M-27 -6 C-22 -22 -12 -38 4 -46 C14 -51 28 -50 38 -42 C28 -41 18 -36 15 -28 C12 -18 20 -9 27 -6 Z" fill="#2E2238"/>
|
||||
<path d="M-25.5 -9 C-24 -13 -22.5 -16 -21 -19 L21.5 -19 C21 -15 23 -11 26 -9 Z" fill="#7A4FC0" stroke="none"/>
|
||||
<rect x="-6" y="-21" width="12" height="13" rx="2" fill="none" stroke="#F2C230" stroke-width="5.40"/></g></svg>
|
||||
|
After Width: | Height: | Size: 564 B |
@@ -0,0 +1,166 @@
|
||||
// Package seasons dresses a site for holidays through the year: a strip along
|
||||
// the top of the page, a prop on the logo and a greeting, worked out in each
|
||||
// visitor's browser from their own date every time a page loads. Nothing is
|
||||
// scheduled and nothing needs a rebuild when a holiday starts or ends.
|
||||
//
|
||||
// The script is src/core.js (the dates), src/render.js (the drawings) and
|
||||
// src/run.js (the page), wrapped here; src/season.css is its stylesheet and
|
||||
// props/ holds a drawing of each prop on its own. List a year's dates with
|
||||
// `TZ=UTC node internal/seasons/src/dates-test.js 2026 2027`.
|
||||
package seasons
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed src/core.js src/render.js src/run.js src/season.css
|
||||
var src embed.FS
|
||||
|
||||
//go:embed props/*.svg
|
||||
var propFS embed.FS
|
||||
|
||||
// Script is the browser script, Style its stylesheet, and Props each prop's
|
||||
// drawing (an SVG laid over the site's logo), by prop name.
|
||||
var (
|
||||
Script []byte
|
||||
Style []byte
|
||||
Props = map[string][]byte{}
|
||||
)
|
||||
|
||||
// IDs are the holidays and December observances a site can name in only:
|
||||
// and except:, in the order the script checks them.
|
||||
var IDs []string
|
||||
|
||||
const header = `/* HotDog CMS seasons: holidays through the year, worked out on the
|
||||
* visitor's own clock every time a page loads (internal/seasons).
|
||||
* Preview: ?season=<holiday id>, ?season=YYYY-MM-DD, ?season=off,
|
||||
* ?season=auto; each lasts for the browser tab's session. */
|
||||
`
|
||||
|
||||
// boot reads the script tag's data-seasons (see Tags) and starts.
|
||||
const boot = `
|
||||
var me = document.currentScript, c = {};
|
||||
try { c = JSON.parse(me.getAttribute('data-seasons')) || {}; } catch (e) {}
|
||||
var props = c.props || {};
|
||||
run({ swap: c.art || [], anchor: c.anchor, skip: c.skip, overlay: c.logo,
|
||||
overlaySrc: function (p) { return props[p]; }, only: c.only, except: c.except,
|
||||
greet: c.greetings !== false, css: false });
|
||||
`
|
||||
|
||||
// overlayCSS places each kind of prop on the logo it's laid over, in
|
||||
// proportion to the logo (drawn for a square one). A site's own stylesheet can
|
||||
// move them: .season-prop-head, -eyes, -ear, -pin, -side.
|
||||
const overlayCSS = `.season-prop{z-index:1;height:auto}
|
||||
.season-prop-head{left:0;top:-31%;width:110%;transform:rotate(-12deg)}
|
||||
.season-prop-eyes{left:5%;top:16.5%;width:95%}
|
||||
.season-prop-ear{left:62%;top:-13%;width:47.5%}
|
||||
.season-prop-pin{left:60%;top:62%;width:47.5%}
|
||||
.season-prop-side{left:-55%;top:-7.5%;width:47.5%}
|
||||
`
|
||||
|
||||
var idRe = regexp.MustCompile(`\bid: '([a-z-]+)'`)
|
||||
|
||||
func init() {
|
||||
read := func(name string) string {
|
||||
b, err := src.ReadFile(name)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
core, render, run := read("src/core.js"), read("src/render.js"), read("src/run.js")
|
||||
Style = []byte(read("src/season.css") + overlayCSS)
|
||||
// The stylesheet is linked, not injected (css: false), so the script's
|
||||
// own copy stays empty.
|
||||
render = strings.Replace(render, " // CSS (the strip's look) comes from season.css, put in by the build.\n", " var CSS = '';\n", 1)
|
||||
Script = []byte(header + "(function () {\n" + core + render + run + boot + "})();\n")
|
||||
|
||||
seen := map[string]bool{}
|
||||
for _, m := range idRe.FindAllStringSubmatch(core, -1) {
|
||||
if !seen[m[1]] {
|
||||
seen[m[1]] = true
|
||||
IDs = append(IDs, m[1])
|
||||
}
|
||||
}
|
||||
entries, err := propFS.ReadDir("props")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, e := range entries {
|
||||
b, err := propFS.ReadFile("props/" + e.Name())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
Props[strings.TrimSuffix(e.Name(), ".svg")] = b
|
||||
}
|
||||
}
|
||||
|
||||
// PropNames lists the props, sorted: the names a site's own art is drawn for.
|
||||
func PropNames() []string {
|
||||
names := make([]string, 0, len(Props))
|
||||
for n := range Props {
|
||||
names = append(names, n)
|
||||
}
|
||||
sort.Strings(names)
|
||||
return names
|
||||
}
|
||||
|
||||
// Known reports whether id names a holiday or an observance.
|
||||
func Known(id string) bool {
|
||||
for _, k := range IDs {
|
||||
if k == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Options is what Tags needs from site.yaml's seasons: block, plus the
|
||||
// addresses of the fingerprinted files.
|
||||
type Options struct {
|
||||
Anchor, Logo, Skip string
|
||||
Art [][2]string // [part of an image's address, address with {p} for the prop]
|
||||
Only, Except []string
|
||||
Greetings bool
|
||||
ScriptURL, CSSURL string
|
||||
PropURLs map[string]string
|
||||
}
|
||||
|
||||
// Tags is the stylesheet link and the script tag for a page's head.
|
||||
func Tags(o Options) (template.HTML, error) {
|
||||
cfg := map[string]any{"props": o.PropURLs}
|
||||
if o.Anchor != "" {
|
||||
cfg["anchor"] = o.Anchor
|
||||
}
|
||||
if o.Logo != "" {
|
||||
cfg["logo"] = o.Logo
|
||||
}
|
||||
if o.Skip != "" {
|
||||
cfg["skip"] = o.Skip
|
||||
}
|
||||
if len(o.Art) > 0 {
|
||||
cfg["art"] = o.Art
|
||||
}
|
||||
if len(o.Only) > 0 {
|
||||
cfg["only"] = o.Only
|
||||
}
|
||||
if len(o.Except) > 0 {
|
||||
cfg["except"] = o.Except
|
||||
}
|
||||
if !o.Greetings {
|
||||
cfg["greetings"] = false
|
||||
}
|
||||
j, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("seasons: %w", err)
|
||||
}
|
||||
esc := template.HTMLEscapeString
|
||||
return template.HTML(`<link rel="stylesheet" href="` + esc(o.CSSURL) + `">` +
|
||||
`<script src="` + esc(o.ScriptURL) + `" defer data-seasons="` + esc(string(j)) + `"></script>`), nil
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package seasons
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScriptAndProps(t *testing.T) {
|
||||
s := string(Script)
|
||||
for _, want := range []string{"function pick(", "function run(", "data-seasons", "var CSS = '';"} {
|
||||
if !strings.Contains(s, want) {
|
||||
t.Errorf("script lacks %q", want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(s, "comes from season.css") {
|
||||
t.Error("the stylesheet placeholder was left in")
|
||||
}
|
||||
for _, id := range []string{"advent", "lunarnewyear", "diwali", "pride", "hanukkah", "christmas", "kwanzaa"} {
|
||||
if !Known(id) {
|
||||
t.Errorf("%s isn't a known holiday", id)
|
||||
}
|
||||
}
|
||||
if Known("arbor") {
|
||||
t.Error("made-up holiday known")
|
||||
}
|
||||
// Every prop a holiday wears has a drawing, and the drawings are plain.
|
||||
for _, p := range regexpAll(`prop: '([a-z]+)'`, s) {
|
||||
if Props[p] == nil {
|
||||
t.Errorf("no drawing for the %s prop", p)
|
||||
}
|
||||
}
|
||||
for name, svg := range Props {
|
||||
low := strings.ToLower(string(svg))
|
||||
if strings.Contains(low, "<script") || strings.Contains(low, " on") || strings.Contains(low, "href") {
|
||||
t.Errorf("%s.svg has script, a handler or a link", name)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(string(Style), ".season-lights{") || !strings.Contains(string(Style), ".season-prop-head{") {
|
||||
t.Error("stylesheet incomplete")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTags(t *testing.T) {
|
||||
h, err := Tags(Options{Anchor: "header", Logo: ".brand-logo", Except: []string{"halloween"},
|
||||
ScriptURL: "/s.js", CSSURL: "/s.css", PropURLs: map[string]string{"santa": "/p/santa.svg"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := string(h)
|
||||
for _, want := range []string{`<link rel="stylesheet" href="/s.css">`, `<script src="/s.js" defer data-seasons="`,
|
||||
`"except":["halloween"]`, `"greetings":false`, `"logo":".brand-logo"`} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Errorf("tags lack %s:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func regexpAll(pat, s string) []string {
|
||||
var out []string
|
||||
for _, m := range regexp.MustCompile(pat).FindAllStringSubmatch(s, -1) {
|
||||
out = append(out, m[1])
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
'use strict';
|
||||
var DAY = 864e5;
|
||||
|
||||
/* ------------------------------------------------------------------ dates
|
||||
* Days are whole numbers counted from 1970-01-01. The visitor's own date
|
||||
* decides almost everything ("today" is where they are); Advent alone runs
|
||||
* on UTC, from Advent Sunday 00:00 UTC. */
|
||||
function dn(y, m, d) { return Math.floor(Date.UTC(y, m - 1, d) / DAY); }
|
||||
function ymd(n) { var t = new Date(n * DAY); return [t.getUTCFullYear(), t.getUTCMonth() + 1, t.getUTCDate()]; }
|
||||
function wday(n) { return new Date(n * DAY).getUTCDay(); }
|
||||
|
||||
// The browser's own calendars (Chinese, Hebrew, Islamic, Persian). Where a
|
||||
// browser lacks one, the holidays on it just don't show.
|
||||
var fmts = {};
|
||||
function cal(c, n) {
|
||||
try {
|
||||
var f = fmts[c];
|
||||
if (f === undefined) {
|
||||
f = new Intl.DateTimeFormat('en-u-ca-' + c + '-nu-latn',
|
||||
{ timeZone: 'UTC', month: c === 'hebrew' ? 'long' : 'numeric', day: 'numeric' });
|
||||
if (f.resolvedOptions().calendar !== c) f = null;
|
||||
fmts[c] = f;
|
||||
}
|
||||
if (!f) return null;
|
||||
var o = {}, p = f.formatToParts(new Date(n * DAY + DAY / 2));
|
||||
for (var i = 0; i < p.length; i++) o[p[i].type] = p[i].value;
|
||||
return { m: o.month, d: +o.day };
|
||||
} catch (e) { return null; }
|
||||
}
|
||||
function isCal(c, n, m, d) { var x = cal(c, n); return !!x && x.m === m && x.d === d; }
|
||||
// The day number in the last `span` days (today included) that is m/d on calendar c.
|
||||
function sinceCal(c, n, m, d, span) {
|
||||
for (var k = 0; k < span; k++) if (isCal(c, n - k, m, d)) return n - k;
|
||||
return null;
|
||||
}
|
||||
|
||||
function easter(y) { // Gregorian (Anonymous Gregorian algorithm)
|
||||
var a = y % 19, b = Math.floor(y / 100), c = y % 100, d = Math.floor(b / 4), e = b % 4,
|
||||
f = Math.floor((b + 8) / 25), g = Math.floor((b - f + 1) / 3), h = (19 * a + b - d - g + 15) % 30,
|
||||
i = Math.floor(c / 4), k = c % 4, l = (32 + 2 * e + 2 * i - h - k) % 7, m = Math.floor((a + 11 * h + 22 * l) / 451),
|
||||
x = h + l - 7 * m + 114;
|
||||
return dn(y, Math.floor(x / 31), x % 31 + 1);
|
||||
}
|
||||
function easterOrthodox(y) { // Julian computus, moved to the Gregorian date (1900-2099: +13)
|
||||
var a = y % 4, b = y % 7, c = y % 19, d = (19 * c + 15) % 30, e = (2 * a + 4 * b - d + 34) % 7, x = d + e + 114;
|
||||
return dn(y, Math.floor(x / 31), x % 31 + 1) + 13;
|
||||
}
|
||||
|
||||
// New and full moons (Meeus, Astronomical Algorithms ch. 49; good to a few
|
||||
// minutes). k whole: a new moon; k + 0.5: a full moon. Returns days since 1970.
|
||||
function moon(k) {
|
||||
var T = k / 1236.85, R = Math.PI / 180, E = 1 - 0.002516 * T;
|
||||
var M = (2.5534 + 29.1053567 * k) * R, P = (201.5643 + 385.81693528 * k) * R, F = (160.7108 + 390.67050284 * k) * R;
|
||||
var full = k % 1 !== 0, s = Math.sin;
|
||||
var c = (full ? -0.40614 : -0.40720) * s(P) + (full ? 0.17302 : 0.17241) * E * s(M) +
|
||||
(full ? 0.01614 : 0.01608) * s(2 * P) + (full ? 0.01043 : 0.01039) * s(2 * F) +
|
||||
(full ? 0.00734 : 0.00739) * E * s(P - M) - (full ? 0.00515 : 0.00514) * E * s(P + M) +
|
||||
(full ? 0.00209 : 0.00208) * E * E * s(2 * M) - 0.00111 * s(P - 2 * F) - 0.00057 * s(P + 2 * F) +
|
||||
0.00056 * E * s(2 * P + M) - 0.00042 * s(3 * P);
|
||||
return 2451550.09766 + 29.530588861 * k + 0.00015437 * T * T + c - 2440587.5;
|
||||
}
|
||||
function inZone(t, hours) { return Math.floor(t + hours / 24); }
|
||||
function newMoonFrom(n, hours) { // the first new moon on or after day n, in that zone
|
||||
var y = ymd(n)[0], k = Math.floor((y - 2000) * 12.3685 + (n - dn(y, 1, 1)) / 29.53) - 2;
|
||||
while (inZone(moon(k), hours) < n) k++;
|
||||
return k;
|
||||
}
|
||||
// Hindu lunisolar dates, as India keeps them (IST). Holi follows the full
|
||||
// moon of Phalguna, the last before the month that holds the sun's entry
|
||||
// into Aries (sidereal); Diwali is the new moon after the sun enters Libra.
|
||||
function holi(y) { return inZone(moon(newMoonFrom(dn(y, 3, 15), 5.5) - 0.5), 5.5); }
|
||||
function diwali(y) { return inZone(moon(newMoonFrom(dn(y, 10, 17), 5.5)), 5.5); }
|
||||
// The December solstice (Meeus ch. 27, mean value; within minutes), as a day in Beijing.
|
||||
function solstice(y) {
|
||||
var Y = (y - 2000) / 1000;
|
||||
return inZone(2451900.05952 + 365242.74049 * Y - 0.06223 * Y * Y - 0.00823 * Y * Y * Y + 0.00032 * Y * Y * Y * Y - 2440587.5, 8);
|
||||
}
|
||||
// The fourth Sunday before Christmas, 00:00 UTC, in ms.
|
||||
function adventStart(y) {
|
||||
var xmas = Date.UTC(y, 11, 25), w = new Date(xmas).getUTCDay();
|
||||
return xmas - ((w || 7) + 21) * DAY;
|
||||
}
|
||||
function lastWday(y, m, w) { var n = dn(y, m + 1, 1) - 1; return n - ((wday(n) - w + 7) % 7); }
|
||||
function between(n, a, b) { return n >= a && n <= b; }
|
||||
|
||||
/* --------------------------------------------------------------- holidays
|
||||
* The first that matches today wins: a strip along the top of the page and
|
||||
* a prop for the mascot. Greetings are [text, language] pairs; several take
|
||||
* turns. */
|
||||
var EN = 'en';
|
||||
var HOLIDAYS = [
|
||||
{ id: 'newyear', strip: 'fireworks', prop: 'tophat',
|
||||
on: function (n, y, m, d) { return (m === 12 && d === 31) || (m === 1 && d <= 2); },
|
||||
greet: [['Happy New Year', EN], ['Feliz Año Nuevo', 'es'], ['Bonne année', 'fr'], ['Frohes neues Jahr', 'de'],
|
||||
['Feliz Ano Novo', 'pt'], ['Felice anno nuovo', 'it'], ['新年快乐', 'zh'], ['あけましておめでとう', 'ja'],
|
||||
['새해 복 많이 받으세요', 'ko'], ['С Новым годом', 'ru'], ['Szczęśliwego Nowego Roku', 'pl'], ['Selamat Tahun Baru', 'id']] },
|
||||
{ id: 'lucia', strip: 'lights', prop: 'lucia',
|
||||
on: function (n, y, m, d) { return m === 12 && d === 13; } },
|
||||
{ id: 'advent', strip: 'lights', prop: 'santa',
|
||||
on: function (n, y, m, d, t) { var u = new Date(t).getUTCFullYear(); return t >= adventStart(u) && t < Date.UTC(u + 1, 0, 1); } },
|
||||
{ id: 'kings', strip: 'lights', prop: 'crown',
|
||||
on: function (n, y, m, d) { return m === 1 && d >= 3 && d <= 7; } },
|
||||
{ id: 'lunarnewyear', strip: 'lanterns', prop: 'lantern',
|
||||
on: function (n) { return isCal('chinese', n + 1, '1', 1) || sinceCal('chinese', n, '1', 1, 3) !== null; },
|
||||
greet: [['新年快乐', 'zh'], ['Chúc mừng năm mới', 'vi'], ['새해 복 많이 받으세요', 'ko'], ['Happy Lunar New Year', EN]] },
|
||||
{ id: 'eidalfitr', strip: 'crescents',
|
||||
on: function (n) { return isCal('islamic-umalqura', n + 1, '10', 1) || sinceCal('islamic-umalqura', n, '10', 1, 3) !== null; },
|
||||
greet: [['عيد مبارك', 'ar'], ['Eid Mubarak', EN], ['Selamat Hari Raya', 'ms'], ['Bayramınız kutlu olsun', 'tr']] },
|
||||
{ id: 'eidaladha', strip: 'crescents',
|
||||
on: function (n) { return isCal('islamic-umalqura', n + 1, '12', 10) || sinceCal('islamic-umalqura', n, '12', 10, 4) !== null; },
|
||||
greet: [['عيد أضحى مبارك', 'ar'], ['Eid al-Adha Mubarak', EN], ['Kurban Bayramınız kutlu olsun', 'tr']] },
|
||||
{ id: 'holi', strip: 'colour', prop: 'holi',
|
||||
on: function (n, y) { return between(n, holi(y) - 1, holi(y) + 1); },
|
||||
greet: [['होली की शुभकामनाएँ', 'hi'], ['Happy Holi', EN]] },
|
||||
{ id: 'nowruz', strip: 'blossom',
|
||||
on: function (n) { return isCal('persian', n + 1, '1', 1) || sinceCal('persian', n, '1', 1, 4) !== null; },
|
||||
greet: [['نوروز مبارک', 'fa'], ['Happy Nowruz', EN], ['Nowruz bayramıňyz gutly bolsun', 'tk']] },
|
||||
{ id: 'carnival', strip: 'streamers', prop: 'mask',
|
||||
on: function (n, y) { var e = easter(y); return between(n, e - 50, e - 47); },
|
||||
greet: [['Feliz Carnaval', 'pt'], ['Happy Carnival', EN], ['Buon Carnevale', 'it']] },
|
||||
{ id: 'easter', strip: 'bunting', prop: 'bunny',
|
||||
on: function (n, y) { var w = easter(y), o = easterOrthodox(y); return between(n, w, w + 1) || between(n, o, o + 1); },
|
||||
greet: function (n, y) {
|
||||
var o = easterOrthodox(y), w = easter(y);
|
||||
var west = [['Happy Easter', EN], ['Frohe Ostern', 'de'], ['Joyeuses Pâques', 'fr'], ['Felices Pascuas', 'es'], ['Buona Pasqua', 'it'], ['Wesołych Świąt', 'pl']];
|
||||
var east = [['Христос воскресе!', 'ru'], ['Χριστός ανέστη!', 'el'], ['Hristos a înviat!', 'ro']];
|
||||
return between(n, o, o + 1) ? (o === w ? west.concat(east) : east.concat([['Happy Orthodox Easter', EN]])) : west;
|
||||
} },
|
||||
{ id: 'songkran', strip: 'water', prop: 'goggles',
|
||||
on: function (n, y, m, d) { return m === 4 && d >= 13 && d <= 15; },
|
||||
greet: [['สุขสันต์วันสงกรานต์', 'th'], ['Happy Songkran', EN], ['Happy Thingyan', EN], ['Suosdei Chnam Thmey', 'km']] },
|
||||
{ id: 'midsummer', strip: 'leaves', prop: 'flowers',
|
||||
on: function (n, y) { var f = dn(y, 6, 19) + ((5 - wday(dn(y, 6, 19)) + 7) % 7); return between(n, f, f + 1); },
|
||||
greet: [['Glad midsommar', 'sv'], ['Hyvää juhannusta', 'fi'], ['Gode sankthans', 'no'], ['Līgo!', 'lv'], ['Happy Midsummer', EN]] },
|
||||
{ id: 'sysadmin', prop: 'shades',
|
||||
on: function (n, y) { return n === lastWday(y, 7, 5); },
|
||||
greet: [['Thank your sysadmin today', EN]] },
|
||||
{ id: 'linux', prop: 'birthday',
|
||||
on: function (n, y, m, d) { return m === 8 && d === 25; },
|
||||
greet: function (n, y) { return [['Happy birthday, Linux: ' + (y - 1991) + ' today', EN]]; } },
|
||||
{ id: 'programmer', strip: 'hex',
|
||||
on: function (n, y) { return n === dn(y, 1, 1) + 255; },
|
||||
greet: [['Happy Day of the Programmer', EN], ['С Днём программиста', 'ru']] },
|
||||
{ id: 'midautumn', strip: 'moonlanterns', prop: 'mlantern',
|
||||
on: function (n) { return sinceCal('chinese', n + 1, '8', 15, 3) !== null; },
|
||||
greet: [['中秋节快乐', 'zh'], ['즐거운 추석 보내세요', 'ko'], ['Tết Trung Thu vui vẻ', 'vi'], ['Happy Mid-Autumn', EN]] },
|
||||
{ id: 'remembrance', prop: 'poppy',
|
||||
on: function (n, y, m, d) { return m === 11 && d === 11; },
|
||||
greet: [['Lest we forget', EN], ['Nous nous souviendrons', 'fr']] },
|
||||
{ id: 'diwali', strip: 'diyas',
|
||||
on: function (n, y) { var x = diwali(y); return between(n, x - 3, x + 2); },
|
||||
greet: [['शुभ दीपावली', 'hi'], ['Happy Diwali', EN], ['தீபாவளி நல்வாழ்த்துகள்', 'ta'], ['Bandi Chhor Divas', 'pa-Latn']] },
|
||||
{ id: 'halloween', strip: 'bats', prop: 'witch',
|
||||
on: function (n, y, m, d) { return m === 10 && d >= 29; },
|
||||
greet: [['Happy Halloween', EN]] },
|
||||
{ id: 'muertos', strip: 'papel', prop: 'marigold',
|
||||
on: function (n, y, m, d) { return m === 11 && d <= 2; },
|
||||
greet: [['Día de Muertos', 'es']] },
|
||||
// Pride Month: all of June, under every single-day holiday (they keep
|
||||
// their day; everyone is still greeted).
|
||||
{ id: 'pride', strip: 'pride', prop: 'pride',
|
||||
on: function (n, y, m) { return m === 6; },
|
||||
greet: [['Happy Pride', EN], ['Feliz Orgullo', 'es'], ['Bonne fierté', 'fr'], ['Feliz Orgulho', 'pt'], ['Fijne Pride', 'nl'], ['Buon Pride', 'it'], ['Happy Pride Month', EN]] }
|
||||
];
|
||||
|
||||
/* December's observances, each drawn the way its own tradition draws it, at
|
||||
* the end of the string of lights. Several can share a day. */
|
||||
var KWANZAA = [['Umoja', 'unity'], ['Kujichagulia', 'self-determination'], ['Ujima', 'collective work and responsibility'],
|
||||
['Ujamaa', 'cooperative economics'], ['Nia', 'purpose'], ['Kuumba', 'creativity'], ['Imani', 'faith']];
|
||||
var SCENES = [
|
||||
{ id: 'hanukkah', tint: 'hanukkah',
|
||||
// Candles are lit at nightfall: the day of 24 Kislev shows the first, and
|
||||
// the eighth stays up through the last day.
|
||||
on: function (n) { var s = sinceCal('hebrew', n, 'Kislev', 24, 9); return s === null ? false : Math.min(8, n - s + 1); },
|
||||
greet: [['חג חנוכה שמח', 'he'], ['Happy Hanukkah', EN]] },
|
||||
{ id: 'sinterklaas', on: function (n, y, m, d) { return m === 12 && (d === 5 || d === 6); },
|
||||
greet: [['Fijne Sinterklaas', 'nl'], ['Happy Sinterklaas', EN]] },
|
||||
{ id: 'bodhi', on: function (n, y, m, d) { return m === 12 && d === 8; },
|
||||
greet: [['Happy Bodhi Day', EN], ['成道会', 'ja']] },
|
||||
{ id: 'lucia', on: function (n, y, m, d) { return m === 12 && d === 13; },
|
||||
greet: [['Glad Lucia', 'sv'], ['Happy St Lucia’s Day', EN]] },
|
||||
{ id: 'posadas', on: function (n, y, m, d) { return m === 12 && d >= 16 && d <= 24; },
|
||||
greet: [['¡Felices Posadas!', 'es']] },
|
||||
{ id: 'yalda', on: function (n) { return isCal('persian', n, '9', 30); },
|
||||
greet: [['شب یلدا مبارک', 'fa'], ['Happy Yalda', EN]] },
|
||||
{ id: 'dongzhi', on: function (n, y) { return n === solstice(y); },
|
||||
greet: [['冬至快乐', 'zh'], ['Happy solstice', EN]] },
|
||||
{ id: 'christmas', on: function (n, y, m, d) { return m === 12 && d >= 24 && d <= 26; },
|
||||
greet: [['Merry Christmas', EN], ['Feliz Navidad', 'es'], ['Joyeux Noël', 'fr'], ['Frohe Weihnachten', 'de'],
|
||||
['Buon Natale', 'it'], ['Feliz Natal', 'pt'], ['God jul', 'sv'], ['Wesołych Świąt', 'pl'], ['Vrolijk kerstfeest', 'nl'],
|
||||
['Nollaig Shona', 'ga'], ['Nadolig Llawen', 'cy'], ['Maligayang Pasko', 'fil'], ['Selamat Hari Natal', 'id'],
|
||||
['メリークリスマス', 'ja'], ['圣诞快乐', 'zh'], ['메리 크리스마스', 'ko']] },
|
||||
{ id: 'kwanzaa',
|
||||
on: function (n, y, m, d) { return m === 12 && d >= 26 ? d - 25 : (m === 1 && d === 1 ? 7 : false); },
|
||||
greet: function (n, y, k) { return [['Habari gani? ' + KWANZAA[k - 1][0], 'sw'], ['Kwanzaa: ' + KWANZAA[k - 1][1], EN]]; } },
|
||||
{ id: 'reyes', on: function (n, y, m, d) { return m === 1 && d === 6; },
|
||||
greet: [['¡Feliz Día de Reyes!', 'es'], ['Happy Epiphany', EN]] },
|
||||
{ id: 'genna', on: function (n, y, m, d) { return m === 1 && d === 7; },
|
||||
greet: [['С Рождеством Христовым', 'ru'], ['Srećan Božić', 'sr-Latn'], ['መልካም ገና', 'am'], ['Merry Christmas', EN]] }
|
||||
];
|
||||
|
||||
// What shows at time t (ms): the holiday (or null) and December's scenes.
|
||||
// A forced holiday id stands in for the date's own.
|
||||
// ok (optional) says which holiday and scene ids the site wants.
|
||||
function pick(t, forced, ok) {
|
||||
ok = ok || function () { return true; };
|
||||
var lt = new Date(t), n = dn(lt.getFullYear(), lt.getMonth() + 1, lt.getDate()), x = ymd(n);
|
||||
var hol = null, scenes = [], i, v;
|
||||
var also = []; // every holiday today: the first dresses the page, all of them are greeted
|
||||
for (i = 0; i < HOLIDAYS.length; i++)
|
||||
if (forced ? HOLIDAYS[i].id === forced : ok(HOLIDAYS[i].id) && HOLIDAYS[i].on(n, x[0], x[1], x[2], t)) { if (!hol) hol = HOLIDAYS[i]; also.push(HOLIDAYS[i]); }
|
||||
for (i = 0; i < SCENES.length; i++) {
|
||||
v = ok(SCENES[i].id) && SCENES[i].on(n, x[0], x[1], x[2], t);
|
||||
if (v) scenes.push({ s: SCENES[i], v: v });
|
||||
}
|
||||
var greet = [];
|
||||
function add(g, k) { greet = greet.concat(typeof g === 'function' ? g(n, x[0], k) : g); }
|
||||
for (i = 0; i < scenes.length; i++) add(scenes[i].s.greet, scenes[i].v);
|
||||
for (i = 0; i < also.length; i++) if (also[i].greet) add(also[i].greet);
|
||||
return { n: n, hol: hol, scenes: scenes, greet: greet };
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Lists every holiday and scene day for some years (run with TZ=UTC).
|
||||
const fs = require('fs');
|
||||
const api = new Function(fs.readFileSync(__dirname + '/core.js', 'utf8') + '; return {pick, holi, diwali, solstice, easter, easterOrthodox, dn, ymd};')();
|
||||
const years = process.argv.slice(2).map(Number);
|
||||
for (const y of years) {
|
||||
const runs = {};
|
||||
for (let n = api.dn(y, 1, 1); n <= api.dn(y, 12, 31); n++) {
|
||||
const r = api.pick(n * 864e5 + 12 * 36e5);
|
||||
const tag = (r.hol ? r.hol.id : '') ;
|
||||
const add = (k, v) => { (runs[k] = runs[k] || []).push(v); };
|
||||
const iso = new Date(n * 864e5).toISOString().slice(5, 10);
|
||||
if (tag) add(tag, iso);
|
||||
for (const s of r.scenes) add('·' + s.s.id, iso + (s.v === true ? '' : '(' + s.v + ')'));
|
||||
}
|
||||
console.log('== ' + y);
|
||||
for (const [k, v] of Object.entries(runs)) console.log(k.padEnd(14), v.length > 8 ? v[0] + ' … ' + v[v.length - 1] + ' (' + v.length + ')' : v.join(' '));
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
|
||||
/* --------------------------------------------------------------- drawing
|
||||
* Everything is drawn here, in SVG, 34px tall, sized to the window. */
|
||||
var NS = 'http://www.w3.org/2000/svg', H = 34;
|
||||
function el(name, attrs, parent) {
|
||||
var e = document.createElementNS(NS, name);
|
||||
for (var k in attrs) e.setAttribute(k, attrs[k]);
|
||||
if (parent) parent.appendChild(e);
|
||||
return e;
|
||||
}
|
||||
function g(parent, x, y, extra) { return el('g', Object.assign({ transform: 'translate(' + x.toFixed(1) + ' ' + y.toFixed(1) + ')' + (extra || '') }, {}), parent); }
|
||||
function anim(parent, x, y, cls, extra) { var o = g(parent, x, y, extra); return el('g', { class: cls }, o); }
|
||||
// A wire that swoops between hooks `span` apart, ending at `w`; calls hang(x, y, i)
|
||||
// at every hook and every dip.
|
||||
function wire(s, w, span, color, hang) {
|
||||
var n = Math.ceil(w / span), d = 'M0 3', i;
|
||||
for (i = 0; i < n; i++) d += ' Q' + (i * span + span / 2) + ' 19 ' + (i + 1) * span + ' 3';
|
||||
el('path', { d: d, fill: 'none', stroke: color || '#3f6b4b', 'stroke-width': 1.8, 'stroke-linecap': 'round' }, s);
|
||||
for (i = 0; i < n * 2; i++) {
|
||||
var x = i * span / 2 + span / 4;
|
||||
if (x > w) break;
|
||||
var y = 3 + 16 * (1 - Math.pow(2 * ((x % span) / span) - 1, 2)) * 0.5;
|
||||
hang(x, y, i);
|
||||
}
|
||||
}
|
||||
var BULB = 'M0 3.2 C3.6 3.6 4.4 8 3 11 C2.2 12.8 1 14 0 14.4 C-1 14 -2.2 12.8 -3 11 C-4.4 8 -3.6 3.6 0 3.2 Z';
|
||||
var PALETTES = {
|
||||
classic: ['#ff4b4b', '#ffcc3d', '#35d36a', '#4b9bff', '#ff8a2a'],
|
||||
hanukkah: ['#4b9bff', '#f4f8ff', '#2f6fe0', '#cfe3ff', '#7fb6ff'],
|
||||
// Hanukkah and Christmas on the same day: both strings, bulb by bulb.
|
||||
shared: ['#ff4b4b', '#4b9bff', '#ffcc3d', '#f4f8ff', '#35d36a', '#2f6fe0', '#ff8a2a', '#cfe3ff', '#ff4b4b', '#7fb6ff']
|
||||
};
|
||||
var STRIPS = {
|
||||
lights: function (s, w, o) {
|
||||
var pal = PALETTES[o.tint] || PALETTES.classic, nb = pal.length;
|
||||
wire(s, w, 88, '#3f6b4b', function (x, y, i) {
|
||||
var b = g(s, x, y, ' rotate(' + ((i % 2 ? 1 : -1) * (8 + (i * 7) % 9)) + ') scale(1.3)');
|
||||
el('rect', { x: -2.2, y: 0, width: 4.4, height: 4, rx: 1, fill: '#3f6b4b' }, b);
|
||||
el('path', { d: BULB, fill: pal[i % nb], style: 'filter:drop-shadow(0 0 3px ' + pal[i % nb] + ')', class: 'tw d' + (i % 4) }, b);
|
||||
});
|
||||
},
|
||||
// Pride Month
|
||||
pride: function (s, w) { // a ribbon in all eleven Progress Pride colours
|
||||
var cols = ['#000000', '#613915', '#5BCEFA', '#F5A9B8', '#FFFFFF', '#E40303', '#FF8C00', '#FFED00', '#008026', '#24408E', '#732982'];
|
||||
for (var k = 0; k < cols.length; k++) {
|
||||
var y0 = 3 + k * 1.9, d = 'M0 ' + y0;
|
||||
for (var x = 0; x <= w + 120; x += 120) d += ' q30 8 60 0 t60 0';
|
||||
el('path', { d: d, fill: 'none', stroke: cols[k], 'stroke-width': 2.1, 'stroke-linecap': 'butt' }, s);
|
||||
}
|
||||
},
|
||||
fireworks: function (s, w) {
|
||||
var cols = ['#ffd23f', '#ff5fa2', '#7fe3ff', '#9b7bff', '#5ee08a'];
|
||||
for (var x = 24, i = 0; x < w; x += 58 + (i * 23) % 31, i++) {
|
||||
var b = anim(s, x, 8 + (i * 13) % 16, 'burst d' + (i % 4)), c = cols[i % 5], r = 6 + (i * 5) % 5;
|
||||
for (var a = 0; a < 12; a++) {
|
||||
var t = a * Math.PI / 6;
|
||||
el('line', { x1: Math.cos(t) * r * 0.35, y1: Math.sin(t) * r * 0.35, x2: Math.cos(t) * r, y2: Math.sin(t) * r,
|
||||
stroke: c, 'stroke-width': 1.6, 'stroke-linecap': 'round' }, b);
|
||||
}
|
||||
el('circle', { r: 1.6, fill: '#fff' }, b);
|
||||
}
|
||||
},
|
||||
lanterns: function (s, w) {
|
||||
wire(s, w, 96, '#8a2b1a', function (x, y, i) {
|
||||
if (i % 2) return;
|
||||
var b = anim(s, x, y, 'sway d' + (i % 4));
|
||||
el('line', { x1: 0, y1: 0, x2: 0, y2: 3, stroke: '#8a2b1a', 'stroke-width': 1 }, b);
|
||||
el('rect', { x: -4, y: 3, width: 8, height: 2.4, rx: 1, fill: '#f2c230' }, b);
|
||||
el('ellipse', { cx: 0, cy: 12, rx: 8, ry: 7.4, fill: '#d62839', style: 'filter:drop-shadow(0 0 3px #ff6a3d)' }, b);
|
||||
el('ellipse', { cx: 0, cy: 12, rx: 3.6, ry: 7.4, fill: 'none', stroke: '#a51c2c', 'stroke-width': 0.8 }, b);
|
||||
el('rect', { x: -4, y: 18.6, width: 8, height: 2.4, rx: 1, fill: '#f2c230' }, b);
|
||||
el('path', { d: 'M-1.2 21 L-1.6 28 L1.6 28 L1.2 21 Z', fill: '#f2c230' }, b);
|
||||
});
|
||||
},
|
||||
moonlanterns: function (s, w) {
|
||||
el('circle', { cx: Math.min(w - 40, w * 0.12 + 20), cy: 14, r: 10, fill: '#fff3c4', style: 'filter:drop-shadow(0 0 6px #ffe08a)' }, s);
|
||||
wire(s, w, 96, '#7a4a1f', function (x, y, i) {
|
||||
if (i % 2) return;
|
||||
var b = anim(s, x, y, 'sway d' + (i % 4));
|
||||
el('line', { x1: 0, y1: 0, x2: 0, y2: 3, stroke: '#7a4a1f', 'stroke-width': 1 }, b);
|
||||
el('circle', { cx: 0, cy: 11, r: 7.5, fill: ['#ffc94a', '#ff9a3c', '#ffde7a'][i / 2 % 3], style: 'filter:drop-shadow(0 0 4px #ffb340)' }, b);
|
||||
el('path', { d: 'M-1 18 L-1.4 25 L1.4 25 L1 18 Z', fill: '#e5412b' }, b);
|
||||
});
|
||||
},
|
||||
streamers: function (s, w) {
|
||||
var cols = ['#ff4fa3', '#ffd23f', '#2bb3a8', '#7b3fb0', '#3b8cff'];
|
||||
for (var k = 0; k < 3; k++) {
|
||||
var d = 'M0 ' + (6 + k * 6);
|
||||
for (var x = 0; x <= w + 40; x += 40) d += ' Q' + (x + 10) + ' ' + (k % 2 ? 0 : 12 + k * 6) + ' ' + (x + 20) + ' ' + (6 + k * 6) + ' T' + (x + 40) + ' ' + (6 + k * 6);
|
||||
el('path', { d: d, fill: 'none', stroke: cols[k], 'stroke-width': 2.4, 'stroke-linecap': 'round', opacity: 0.9 }, s);
|
||||
}
|
||||
for (var i = 0, xx = 9; xx < w; xx += 17 + (i * 7) % 11, i++)
|
||||
el('rect', { x: xx, y: 4 + (i * 11) % 26, width: 3.4, height: 5.4, rx: 1, fill: cols[(i + 2) % 5],
|
||||
transform: 'rotate(' + ((i * 37) % 90 - 45) + ' ' + xx + ' ' + (6 + (i * 11) % 26) + ')', class: 'tw d' + (i % 4) }, s);
|
||||
},
|
||||
bunting: function (s, w) {
|
||||
var cols = ['#f7a8c4', '#bde3a3', '#a8d8f7', '#ffe08a', '#d6c1f5'];
|
||||
wire(s, w, 44, '#c9a27a', function (x, y, i) {
|
||||
el('path', { d: 'M' + (x - 9) + ' ' + (y - 1) + ' L' + (x + 9) + ' ' + (y - 1) + ' L' + x + ' ' + (y + 16) + ' Z', fill: cols[i % 5] }, s);
|
||||
});
|
||||
},
|
||||
water: function (s, w) {
|
||||
for (var x = 10, i = 0; x < w; x += 22 + (i * 9) % 13, i++) {
|
||||
var b = anim(s, x, 2 + (i * 7) % 10, 'drip d' + (i % 4));
|
||||
el('path', { d: 'M0 0 C3 5 5 8 5 11 A5 5 0 0 1 -5 11 C-5 8 -3 5 0 0 Z', fill: ['#5cc8ff', '#2d9cff', '#9be3ff'][i % 3], opacity: 0.9 }, b);
|
||||
el('path', { d: 'M-2 10 a2.4 2.4 0 0 0 1.6 2.6', stroke: '#fff', 'stroke-width': 1, fill: 'none' }, b);
|
||||
}
|
||||
},
|
||||
crescents: function (s, w) {
|
||||
wire(s, w, 80, '#b08a2e', function (x, y, i) {
|
||||
var b = anim(s, x, y, 'tw d' + (i % 4));
|
||||
el('line', { x1: 0, y1: 0, x2: 0, y2: 4, stroke: '#b08a2e', 'stroke-width': 1 }, b);
|
||||
if (i % 2) el('path', { d: 'M0 5 L1.8 9.6 L6.6 9.8 L2.8 12.8 L4.2 17.4 L0 14.8 L-4.2 17.4 L-2.8 12.8 L-6.6 9.8 L-1.8 9.6 Z', fill: '#f2c230', style: 'filter:drop-shadow(0 0 3px #ffd86a)' }, b);
|
||||
else el('path', { d: 'M3 5 A8 8 0 1 0 3 21 A6.2 6.2 0 1 1 3 5 Z', fill: '#f2c230', style: 'filter:drop-shadow(0 0 3px #ffd86a)' }, b);
|
||||
});
|
||||
},
|
||||
leaves: function (s, w) {
|
||||
wire(s, w, 70, '#3b7d2c', function (x, y, i) {
|
||||
if (i % 3 === 2) {
|
||||
var f = g(s, x, y + 5);
|
||||
for (var a = 0; a < 6; a++) el('circle', { cx: Math.cos(a * 1.047) * 3.2, cy: Math.sin(a * 1.047) * 3.2, r: 2.4, fill: i % 2 ? '#ffffff' : '#6c8ef5' }, f);
|
||||
el('circle', { r: 1.8, fill: '#ffc83d' }, f);
|
||||
} else el('path', { d: 'M' + x + ' ' + y + ' q6 4 2 13 q-7 -5 -2 -13 Z', fill: ['#5aa83c', '#7cc35a', '#3f8f2e'][i % 3],
|
||||
transform: 'rotate(' + (i % 2 ? 25 : -25) + ' ' + x + ' ' + y + ')' }, s);
|
||||
});
|
||||
},
|
||||
hex: function (s, w) {
|
||||
var t = el('text', { x: 6, y: 21, fill: '#3bd16f', 'font-family': 'ui-monospace, Menlo, Consolas, monospace', 'font-size': 12, opacity: 0.85 }, s);
|
||||
var unit = '0x100 · 256 · 0b100000000 · 0o400 · ', str = '';
|
||||
while (str.length * 7.3 < w) str += unit;
|
||||
t.textContent = str;
|
||||
},
|
||||
bats: function (s, w) {
|
||||
wire(s, w, 90, '#4a3a5a', function (x, y, i) {
|
||||
if (i % 2) {
|
||||
var p = g(s, x, y);
|
||||
el('line', { x1: 0, y1: 0, x2: 0, y2: 3, stroke: '#4a3a5a', 'stroke-width': 1 }, p);
|
||||
el('ellipse', { cx: 0, cy: 10, rx: 7.5, ry: 6.5, fill: '#ff8a1f', style: 'filter:drop-shadow(0 0 3px #ffb347)' }, p);
|
||||
el('path', { d: 'M-3 9 l2 -2 l0 3 Z M3 9 l-2 -2 l0 3 Z M-3 12.5 q3 2 6 0', fill: '#3a2410', stroke: '#3a2410', 'stroke-width': 0.6 }, p);
|
||||
el('rect', { x: -1, y: 2.4, width: 2, height: 2.6, fill: '#3f6b2a' }, p);
|
||||
} else {
|
||||
var b = anim(s, x, y + 10, 'flap d' + (i % 4));
|
||||
el('path', { d: 'M0 0 C-3 -4 -7 -4 -11 -1 C-9 0 -8 2 -7 3 C-5 1 -3 2 -1.5 3 Z M0 0 C3 -4 7 -4 11 -1 C9 0 8 2 7 3 C5 1 3 2 1.5 3 Z M-1.6 -2 L-1 -4 L0 -2.4 L1 -4 L1.6 -2 Z', fill: '#3a2d4a', stroke: '#9c86c4', 'stroke-width': 0.6 }, b);
|
||||
}
|
||||
});
|
||||
},
|
||||
papel: function (s, w) {
|
||||
var cols = ['#ff4fa3', '#ff8a1f', '#ffd23f', '#3bd16f', '#3b8cff', '#9b5cff'];
|
||||
el('line', { x1: 0, y1: 2, x2: w, y2: 2, stroke: '#6b4a2a', 'stroke-width': 1.2 }, s);
|
||||
for (var x = 2, i = 0; x < w; x += 26, i++) {
|
||||
var f = g(s, x, 2);
|
||||
var d = 'M0 0 H22 V18 l-2.75 3 l-2.75 -3 l-2.75 3 l-2.75 -3 l-2.75 3 l-2.75 -3 l-2.75 3 l-2.75 -3 Z';
|
||||
d += ' M11 5 l2 3 l-2 3 l-2 -3 Z M5 9 a1.6 1.6 0 1 0 0.01 0 Z M17 9 a1.6 1.6 0 1 0 0.01 0 Z M7 14 h8 v1.6 h-8 Z';
|
||||
el('path', { d: d, fill: cols[i % 6], 'fill-rule': 'evenodd', opacity: 0.95 }, f);
|
||||
}
|
||||
},
|
||||
diyas: function (s, w) {
|
||||
wire(s, w, 76, '#e8891c', function (x, y, i) {
|
||||
if (i % 2) {
|
||||
var b = g(s, x, y + 2);
|
||||
el('path', { d: 'M-8 6 Q0 15 8 6 Z', fill: '#c8541a' }, b);
|
||||
el('path', { d: 'M-8 6 Q0 9 8 6', stroke: '#f2c230', 'stroke-width': 1, fill: 'none' }, b);
|
||||
el('path', { d: 'M0 -4 C2.6 0 2.6 3 0 6 C-2.6 3 -2.6 0 0 -4 Z', fill: '#ffcf3d', class: 'flick d' + (i % 4), style: 'filter:drop-shadow(0 0 4px #ffb020)' }, b);
|
||||
} else for (var k = 0; k < 3; k++)
|
||||
el('circle', { cx: x + (k - 1) * 6, cy: y + 1 + Math.abs(k - 1) * -1.2, r: 3, fill: k === 1 ? '#ffb627' : '#f08a1c' }, s);
|
||||
});
|
||||
},
|
||||
colour: function (s, w) {
|
||||
var cols = ['#ff4fa3', '#ffc21a', '#3bd16f', '#3b8cff', '#9b5cff', '#ff7a1f'];
|
||||
for (var x = 6, i = 0; x < w; x += 18 + (i * 13) % 19, i++) {
|
||||
var c = cols[i % 6], y = 6 + (i * 17) % 20, r = 4 + (i * 3) % 5;
|
||||
el('circle', { cx: x, cy: y, r: r, fill: c, opacity: 0.75, style: 'filter:blur(1.2px)' }, s);
|
||||
el('circle', { cx: x + r, cy: y - r * 0.6, r: r * 0.4, fill: c, opacity: 0.7 }, s);
|
||||
el('circle', { cx: x - r * 0.9, cy: y + r * 0.8, r: r * 0.3, fill: c, opacity: 0.7 }, s);
|
||||
}
|
||||
},
|
||||
blossom: function (s, w) {
|
||||
var d = 'M0 6', x;
|
||||
for (x = 0; x <= w; x += 60) d += ' Q' + (x + 30) + ' ' + (x / 60 % 2 ? 2 : 14) + ' ' + (x + 60) + ' 8';
|
||||
el('path', { d: d, fill: 'none', stroke: '#7a5236', 'stroke-width': 2, 'stroke-linecap': 'round' }, s);
|
||||
for (var i = 0, xx = 8; xx < w; xx += 21 + (i * 7) % 9, i++) {
|
||||
var f = g(s, xx, 7 + (i * 5) % 10);
|
||||
if (i % 4 === 3) { el('path', { d: 'M0 0 q4 2 3 8 q-5 -3 -3 -8 Z', fill: '#6cbf4b' }, f); continue; }
|
||||
for (var a = 0; a < 5; a++) el('circle', { cx: Math.cos(a * 1.2566 - 1.57) * 3, cy: Math.sin(a * 1.2566 - 1.57) * 3, r: 2.6, fill: i % 2 ? '#ffd1e3' : '#ffffff', stroke: '#f2a6c4', 'stroke-width': 0.5 }, f);
|
||||
el('circle', { r: 1.3, fill: '#e8608f' }, f);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// December's scenes: [width, draw(g, value)].
|
||||
function flame(p, x, y, i) {
|
||||
el('path', { d: 'M' + x + ' ' + (y - 5.5) + ' c2 3 2 4.6 0 5.5 c-2 -0.9 -2 -2.5 0 -5.5 Z', fill: '#ffcf3d', class: 'flick d' + (i % 4), style: 'filter:drop-shadow(0 0 3px #ffb020)' }, p);
|
||||
}
|
||||
var SCENE_ART = {
|
||||
hanukkah: [62, function (p, nights) {
|
||||
// A hanukkiah: eight candles and the shamash, raised in the middle.
|
||||
// Candles are set from the right; tonight's newest is lit first.
|
||||
el('path', { d: 'M31 32 V22 M18 32 h26 M4 18 Q4 24 31 24 Q58 24 58 18', fill: 'none', stroke: '#c9a227', 'stroke-width': 2, 'stroke-linecap': 'round' }, p);
|
||||
for (var j = 0; j < 9; j++) {
|
||||
var x = j < 4 ? 4 + j * 6.4 : (j === 4 ? 31 : 58 - (8 - j) * 6.4), sham = j === 4, top = sham ? 6 : 10;
|
||||
el('rect', { x: x - 1.6, y: top, width: 3.2, height: sham ? 12 : 8, rx: 1, fill: '#eaf3ff', stroke: '#7fb6ff', 'stroke-width': 0.6 }, p);
|
||||
var slot = j < 4 ? j : j - 1; // 0..7 left to right, without the shamash
|
||||
if (sham || slot >= 8 - nights) flame(p, x, top, j);
|
||||
}
|
||||
}],
|
||||
sinterklaas: [40, function (p) {
|
||||
el('path', { d: 'M3 26 C3 20 10 18 16 18 L26 17 C30 16 32 13 36 14 C39 15 38 22 35 26 C30 31 8 31 3 26 Z', fill: '#f1c26b', stroke: '#9a6a2a', 'stroke-width': 1 }, p);
|
||||
el('path', { d: 'M17 17 L28 4 L31 6 L21 18 Z', fill: '#ff8a1f', stroke: '#c25a00', 'stroke-width': 0.8 }, p);
|
||||
el('path', { d: 'M28 4 l-1 -3 M28 4 l3 -2 M28 4 l2 -4', stroke: '#4e9a3a', 'stroke-width': 1.4, 'stroke-linecap': 'round' }, p);
|
||||
}],
|
||||
bodhi: [30, function (p) {
|
||||
el('path', { d: 'M15 3 C19 8 27 9 27 17 C27 24 20 26 15 33 C10 26 3 24 3 17 C3 9 11 8 15 3 Z', fill: '#5aa83c', stroke: '#2f6f22', 'stroke-width': 1 }, p);
|
||||
el('path', { d: 'M15 6 V31 M15 14 l-6 -3 M15 14 l6 -3 M15 20 l-7 -3 M15 20 l7 -3 M15 26 l-5 -3 M15 26 l5 -3', stroke: '#d8efc6', 'stroke-width': 0.8, fill: 'none' }, p);
|
||||
}],
|
||||
lucia: [44, function (p) {
|
||||
el('path', { d: 'M2 30 Q22 22 42 30', stroke: '#3e8e3a', 'stroke-width': 3, fill: 'none', 'stroke-linecap': 'round' }, p);
|
||||
for (var j = 0; j < 4; j++) {
|
||||
var x = 7 + j * 10;
|
||||
el('rect', { x: x - 2, y: 12, width: 4, height: 15, rx: 1, fill: '#fbfbf2', stroke: '#c9c3a6', 'stroke-width': 0.6 }, p);
|
||||
flame(p, x, 12, j);
|
||||
}
|
||||
el('circle', { cx: 13, cy: 28, r: 1.6, fill: '#d62839' }, p); el('circle', { cx: 31, cy: 28, r: 1.6, fill: '#d62839' }, p);
|
||||
}],
|
||||
posadas: [56, function (p) {
|
||||
for (var j = 0; j < 2; j++) {
|
||||
var x = 2 + j * 14;
|
||||
el('path', { d: 'M' + x + ' 18 h11 v14 h-11 Z', fill: '#f4d79a', stroke: '#b38a3e', 'stroke-width': 0.8, style: 'filter:drop-shadow(0 0 4px #ffcf6a)' }, p);
|
||||
flame(p, x + 5.5, 28, j);
|
||||
}
|
||||
var st = g(p, 44, 14), d = '';
|
||||
for (var a = 0; a < 14; a++) { var r = a % 2 ? 4 : 11, t = a * Math.PI / 7 - Math.PI / 2; d += (a ? 'L' : 'M') + (Math.cos(t) * r).toFixed(1) + ' ' + (Math.sin(t) * r).toFixed(1); }
|
||||
el('path', { d: d + 'Z', fill: '#ff4fa3', stroke: '#b81e6e', 'stroke-width': 0.8 }, st);
|
||||
el('circle', { r: 4, fill: '#ffd23f' }, st);
|
||||
}],
|
||||
yalda: [40, function (p) {
|
||||
el('circle', { cx: 16, cy: 21, r: 11, fill: '#b5162b', stroke: '#7a0d1c', 'stroke-width': 1 }, p);
|
||||
el('path', { d: 'M12 11 l2 -5 l2 3 l2 -3 l2 5 Z', fill: '#b5162b', stroke: '#7a0d1c', 'stroke-width': 0.8 }, p);
|
||||
el('path', { d: 'M10 18 a6 6 0 0 0 12 6 Z', fill: '#f7d6c8' }, p);
|
||||
for (var j = 0; j < 6; j++) el('circle', { cx: 12.5 + (j % 3) * 3, cy: 21 + Math.floor(j / 3) * 2.6, r: 1.2, fill: '#e01f3d' }, p);
|
||||
el('path', { d: 'M34 6 l1 2.4 l2.4 0.2 l-1.8 1.6 l0.6 2.4 l-2.2 -1.3 l-2.2 1.3 l0.6 -2.4 l-1.8 -1.6 l2.4 -0.2 Z', fill: '#ffe08a' }, p);
|
||||
el('circle', { cx: 30, cy: 22, r: 1.2, fill: '#ffe08a' }, p);
|
||||
}],
|
||||
dongzhi: [42, function (p) {
|
||||
el('circle', { cx: 34, cy: 9, r: 5, fill: '#ffd86a', style: 'filter:drop-shadow(0 0 4px #ffcf3d)' }, p);
|
||||
el('path', { d: 'M2 20 H32 C32 28 26 32 17 32 C8 32 2 28 2 20 Z', fill: '#4b9bff', stroke: '#2b5fb0', 'stroke-width': 1 }, p);
|
||||
el('path', { d: 'M5 24 H29', stroke: '#ffffff', 'stroke-width': 1.2, opacity: 0.8 }, p);
|
||||
el('circle', { cx: 11, cy: 18, r: 4, fill: '#ffffff', stroke: '#d8d8d8', 'stroke-width': 0.6 }, p);
|
||||
el('circle', { cx: 18, cy: 17, r: 4, fill: '#ffd1e3', stroke: '#e3a6bf', 'stroke-width': 0.6 }, p);
|
||||
el('circle', { cx: 25, cy: 18, r: 4, fill: '#ffffff', stroke: '#d8d8d8', 'stroke-width': 0.6 }, p);
|
||||
}],
|
||||
christmas: [32, function (p) {
|
||||
var d = '';
|
||||
for (var a = 0; a < 10; a++) { var r = a % 2 ? 5.5 : 13, t = a * Math.PI / 5 - Math.PI / 2; d += (a ? 'L' : 'M') + (16 + Math.cos(t) * r).toFixed(1) + ' ' + (18 + Math.sin(t) * r).toFixed(1); }
|
||||
el('path', { d: d + 'Z', fill: '#ffd23f', stroke: '#c99a12', 'stroke-width': 1, style: 'filter:drop-shadow(0 0 5px #ffe28a)', class: 'tw d1' }, p);
|
||||
}],
|
||||
kwanzaa: [62, function (p, days) {
|
||||
// A kinara: three red, the black in the middle, three green. The black
|
||||
// is lit first, then the outermost red and green, working inwards.
|
||||
el('rect', { x: 2, y: 26, width: 58, height: 6, rx: 2, fill: '#8a5a2b', stroke: '#5a3a1a', 'stroke-width': 0.8 }, p);
|
||||
var order = [3, 0, 6, 1, 5, 2, 4], lit = order.slice(0, days);
|
||||
var cols = ['#d62839', '#d62839', '#d62839', '#1d1d1d', '#2ba84a', '#2ba84a', '#2ba84a'];
|
||||
for (var j = 0; j < 7; j++) {
|
||||
var x = 7 + j * 8;
|
||||
el('rect', { x: x - 2, y: j === 3 ? 10 : 13, width: 4, height: j === 3 ? 16 : 13, rx: 1, fill: cols[j], stroke: '#00000040', 'stroke-width': 0.5 }, p);
|
||||
if (lit.indexOf(j) !== -1) flame(p, x, j === 3 ? 10 : 13, j);
|
||||
}
|
||||
}],
|
||||
reyes: [34, function (p) {
|
||||
el('path', { d: 'M3 30 L5 12 L11 20 L17 8 L23 20 L29 12 L31 30 Z', fill: '#f2c230', stroke: '#b38a12', 'stroke-width': 1 }, p);
|
||||
el('circle', { cx: 17, cy: 24, r: 2.4, fill: '#d62839' }, p); el('circle', { cx: 9, cy: 25, r: 1.8, fill: '#2d7dd2' }, p); el('circle', { cx: 25, cy: 25, r: 1.8, fill: '#2ba84a' }, p);
|
||||
}],
|
||||
genna: [32, function (p) { SCENE_ART.christmas[1](p); }]
|
||||
};
|
||||
|
||||
// CSS (the strip's look) comes from season.css, put in by the build.
|
||||
|
||||
var PROP_KIND = { santa: 'head', tophat: 'head', crown: 'head', bunny: 'head', flowers: 'head', birthday: 'head',
|
||||
witch: 'head', lucia: 'head', mask: 'eyes', shades: 'eyes', goggles: 'eyes', holi: 'eyes', marigold: 'ear',
|
||||
poppy: 'pin', lantern: 'side', mlantern: 'side', pride: 'pin' };
|
||||
@@ -0,0 +1,188 @@
|
||||
|
||||
/* ---------------------------------------------------------------- the page */
|
||||
// Paints the strip for r (from pick) into box, w px wide; returns a stop().
|
||||
function paint(box, r, w) {
|
||||
while (box.firstChild) box.removeChild(box.firstChild);
|
||||
var svg = el('svg', { width: w, height: H, viewBox: '0 0 ' + w + ' ' + H, focusable: 'false' }, box);
|
||||
var pad = 10, gap = 8, sw = 0, i;
|
||||
for (i = 0; i < r.scenes.length; i++) sw += SCENE_ART[r.scenes[i].s.id][0] + (i ? gap : 0);
|
||||
var x0 = r.scenes.length ? w - pad - sw : w;
|
||||
var strip = r.hol && r.hol.strip, tint = null;
|
||||
for (i = 0; i < r.scenes.length; i++) if (r.scenes[i].s.tint) tint = r.scenes[i].s.tint;
|
||||
for (i = 0; i < r.scenes.length; i++) if (tint && r.scenes[i].s.id === 'christmas') tint = 'shared';
|
||||
if (!strip && r.scenes.length) strip = 'lights';
|
||||
if (strip && STRIPS[strip]) {
|
||||
var sg = el('g', {}, svg);
|
||||
if (r.scenes.length) {
|
||||
var clip = el('clipPath', { id: 'season-clip' }, el('defs', {}, svg));
|
||||
el('rect', { x: 0, y: -10, width: Math.max(0, x0 - gap), height: H + 20 }, clip);
|
||||
sg.setAttribute('clip-path', 'url(#season-clip)');
|
||||
}
|
||||
STRIPS[strip](sg, r.scenes.length ? x0 - gap : w, { tint: tint });
|
||||
}
|
||||
for (var x = x0, j = 0; j < r.scenes.length; j++) {
|
||||
var art = SCENE_ART[r.scenes[j].s.id];
|
||||
art[1](g(svg, x, 0), r.scenes[j].v);
|
||||
x += art[0] + gap;
|
||||
}
|
||||
if (!r.greet.length) return function () {};
|
||||
var pill = document.createElement('span');
|
||||
pill.className = 'season-greet';
|
||||
pill.style.right = (r.scenes.length ? sw + pad + gap : 12) + 'px';
|
||||
box.appendChild(pill);
|
||||
var k = 0, timer;
|
||||
function show() {
|
||||
var gr = r.greet[k % r.greet.length];
|
||||
pill.textContent = gr[0];
|
||||
pill.setAttribute('lang', gr[1]);
|
||||
pill.setAttribute('dir', 'auto');
|
||||
pill.style.opacity = 1;
|
||||
}
|
||||
show();
|
||||
if (r.greet.length > 1) timer = setInterval(function () {
|
||||
pill.style.opacity = 0;
|
||||
setTimeout(function () { k++; show(); }, 400);
|
||||
}, 3600);
|
||||
return function () { clearInterval(timer); };
|
||||
}
|
||||
|
||||
function withVersion(u, v) { return v ? u + (u.indexOf('?') === -1 ? '?' : '&') + 'v=' + v : u; }
|
||||
function resolve(tpl, prop) { return typeof tpl === 'function' ? tpl(prop) : tpl.split('{p}').join(prop); }
|
||||
|
||||
// cfg: swap [[part of the mascot's URL, template with {p} for the prop]],
|
||||
// anchor (" | "-separated selectors; the strip hangs under the first found),
|
||||
// skip (selector: mascots inside keep their usual look), overlay + overlaySrc
|
||||
// (lay the prop over an element that isn't an image), version, only/except
|
||||
// (holiday and scene ids to show, or to leave out), greet (false: no
|
||||
// greetings), css (false: the page links season.css itself).
|
||||
function run(cfg) {
|
||||
var q = null;
|
||||
try {
|
||||
q = new URLSearchParams(location.search).get('season');
|
||||
if (q === 'auto') sessionStorage.removeItem('season');
|
||||
else if (q) sessionStorage.setItem('season', q);
|
||||
q = sessionStorage.getItem('season');
|
||||
} catch (e) { q = null; }
|
||||
if (q === 'off') return;
|
||||
var t = Date.now(), forced = null;
|
||||
if (q && /^\d{4}-\d\d-\d\d$/.test(q)) t = new Date(q + 'T12:00:00').getTime();
|
||||
else if (q === 'on') forced = 'advent';
|
||||
else if (q) forced = q;
|
||||
var only = cfg.only && cfg.only.length ? cfg.only : null, except = cfg.except || [];
|
||||
var r = pick(t, forced, function (id) { return (!only || only.indexOf(id) !== -1) && except.indexOf(id) === -1; });
|
||||
if (cfg.greet === false) r.greet = [];
|
||||
if (!r.hol && !r.scenes.length) return;
|
||||
|
||||
var prop = r.hol && r.hol.prop, swaps = cfg.swap || [], anchor = cfg.anchor, skip = cfg.skip;
|
||||
function hat(img) {
|
||||
if (!prop || !img || img.getAttribute('data-season') || (skip && img.closest(skip))) return;
|
||||
var src = img.getAttribute('src') || '';
|
||||
for (var i = 0; i < swaps.length; i++) if (src.indexOf(swaps[i][0]) !== -1) {
|
||||
img.setAttribute('data-season', src);
|
||||
img.removeAttribute('srcset');
|
||||
img.setAttribute('src', withVersion(resolve(swaps[i][1], prop), cfg.version));
|
||||
return;
|
||||
}
|
||||
}
|
||||
function source(s) { // a <picture>'s <source> wins over its <img>
|
||||
if (!prop || s.getAttribute('data-season') || (skip && s.closest(skip))) return;
|
||||
var set = s.getAttribute('srcset') || '';
|
||||
for (var i = 0; i < swaps.length; i++) if (set.indexOf(swaps[i][0]) !== -1) {
|
||||
s.setAttribute('data-season', set);
|
||||
s.setAttribute('srcset', withVersion(resolve(swaps[i][1], prop), cfg.version));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Where each kind of prop sits on a picture, in parts of its height.
|
||||
var SPOT = { head: [0, -0.31, 1.1], eyes: [0.05, 0.165, 0.95], ear: [0.62, -0.13, 0.475],
|
||||
pin: [0.6, 0.62, 0.475], side: [-0.55, -0.075, 0.475] };
|
||||
function overlay(host) {
|
||||
if (!prop || !cfg.overlay || host.getAttribute('data-season-prop')) return;
|
||||
var src = resolve(cfg.overlaySrc, prop);
|
||||
if (!src) return;
|
||||
host.setAttribute('data-season-prop', prop);
|
||||
// A picture can't hold the prop, so it goes in the picture's parent,
|
||||
// placed over the picture (and placed again when the page resizes).
|
||||
var pic = /^(img|svg|picture)$/i.test(host.tagName), box = pic ? host.parentElement : host;
|
||||
if (!box) return;
|
||||
if (getComputedStyle(box).position === 'static') box.style.position = 'relative';
|
||||
var im = document.createElement('img');
|
||||
im.className = 'season-prop season-prop-' + PROP_KIND[prop] + ' season-prop-is-' + prop;
|
||||
im.alt = '';
|
||||
im.setAttribute('aria-hidden', 'true');
|
||||
im.src = withVersion(src, cfg.version);
|
||||
box.appendChild(im);
|
||||
if (!pic) return;
|
||||
function put() {
|
||||
var a = host.getBoundingClientRect(), b = box.getBoundingClientRect(), s = SPOT[PROP_KIND[prop]], u = a.height;
|
||||
im.style.left = (a.left - b.left + s[0] * u) + 'px';
|
||||
im.style.top = (a.top - b.top + s[1] * u) + 'px';
|
||||
im.style.width = (s[2] * u) + 'px';
|
||||
}
|
||||
put();
|
||||
if (host.tagName === 'IMG' && !host.complete) host.addEventListener('load', put);
|
||||
window.addEventListener('resize', put);
|
||||
}
|
||||
function dress(root) {
|
||||
var scope = root.querySelectorAll ? root : document, i, l;
|
||||
if (swaps.length) {
|
||||
l = scope.querySelectorAll('picture source'); for (i = 0; i < l.length; i++) source(l[i]);
|
||||
l = scope.querySelectorAll('img'); for (i = 0; i < l.length; i++) hat(l[i]);
|
||||
if (root.tagName === 'IMG') hat(root);
|
||||
}
|
||||
if (cfg.overlay) {
|
||||
l = scope.querySelectorAll(cfg.overlay); for (i = 0; i < l.length; i++) overlay(l[i]);
|
||||
if (root.matches && root.matches(cfg.overlay)) overlay(root);
|
||||
}
|
||||
}
|
||||
|
||||
var box;
|
||||
function place() { // under the anchor when it's there, else along the window's top
|
||||
var host = null, list = anchor ? anchor.split(' | ') : [];
|
||||
for (var i = 0; i < list.length && !host; i++) host = document.querySelector(list[i]);
|
||||
if (host) {
|
||||
if (box.parentNode === host) return;
|
||||
box.classList.add('season-anchored');
|
||||
if (getComputedStyle(host).position === 'static') host.style.position = 'relative';
|
||||
host.appendChild(box);
|
||||
} else if (!box.isConnected || box.classList.contains('season-anchored')) {
|
||||
box.classList.remove('season-anchored');
|
||||
document.body.appendChild(box);
|
||||
}
|
||||
}
|
||||
|
||||
function start() {
|
||||
var html = document.documentElement;
|
||||
html.classList.add('season-on');
|
||||
if (r.hol) html.classList.add('season-' + r.hol.id);
|
||||
if (cfg.css !== false) {
|
||||
var st = document.createElement('style');
|
||||
st.textContent = CSS;
|
||||
document.head.appendChild(st);
|
||||
}
|
||||
box = document.createElement('div');
|
||||
box.className = 'season-lights';
|
||||
box.setAttribute('aria-hidden', 'true');
|
||||
var stop = function () {}, lastW = 0;
|
||||
function draw() {
|
||||
var w = Math.max(html.clientWidth, 320);
|
||||
if (w === lastW) return;
|
||||
lastW = w; stop(); stop = paint(box, r, w);
|
||||
}
|
||||
place();
|
||||
draw();
|
||||
var tm;
|
||||
window.addEventListener('resize', function () { clearTimeout(tm); tm = setTimeout(draw, 150); });
|
||||
dress(document);
|
||||
// Pages that build their header after load (or rebuild it) still get
|
||||
// dressed, and the strip moves under its anchor once that exists.
|
||||
new MutationObserver(function (ms) {
|
||||
if (anchor) place();
|
||||
for (var i = 0; i < ms.length; i++)
|
||||
for (var j = 0; j < ms[i].addedNodes.length; j++)
|
||||
if (ms[i].addedNodes[j].nodeType === 1) dress(ms[i].addedNodes[j]);
|
||||
}).observe(document.body, { childList: true, subtree: true });
|
||||
}
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start);
|
||||
else start();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
.season-lights{position:fixed;top:0;left:0;right:0;height:34px;z-index:2147483000;pointer-events:none;overflow:hidden}
|
||||
.season-lights svg{display:block;position:absolute;top:0;left:0;height:34px;overflow:visible}
|
||||
.season-lights .tw{animation:season-tw 2.4s ease-in-out infinite}
|
||||
.season-lights .burst{animation:season-burst 2.8s ease-out infinite;transform-box:fill-box;transform-origin:center}
|
||||
.season-lights .sway{animation:season-sway 3.2s ease-in-out infinite;transform-box:fill-box;transform-origin:top}
|
||||
.season-lights .drip{animation:season-drip 2.6s ease-in infinite}
|
||||
.season-lights .flap{animation:season-flap .5s ease-in-out infinite alternate;transform-box:fill-box;transform-origin:center}
|
||||
.season-lights .flick{animation:season-flick 1.3s ease-in-out infinite;transform-box:fill-box;transform-origin:bottom}
|
||||
.season-lights .d1{animation-delay:-.6s}
|
||||
.season-lights .d2{animation-delay:-1.2s}
|
||||
.season-lights .d3{animation-delay:-1.8s}
|
||||
@keyframes season-tw{0%,100%{opacity:1}50%{opacity:.45}
|
||||
}
|
||||
@keyframes season-burst{0%{opacity:0;transform:scale(.3)}25%{opacity:1;transform:scale(1)}70%{opacity:.8}100%{opacity:0;transform:scale(1.15)}
|
||||
}
|
||||
@keyframes season-sway{0%,100%{transform:rotate(-5deg)}50%{transform:rotate(5deg)}
|
||||
}
|
||||
@keyframes season-drip{0%{opacity:0;transform:translateY(-4px)}20%{opacity:1}100%{opacity:0;transform:translateY(10px)}
|
||||
}
|
||||
@keyframes season-flap{from{transform:scaleY(1)}to{transform:scaleY(.55)}
|
||||
}
|
||||
@keyframes season-flick{0%,100%{transform:scale(1)}50%{transform:scale(.85,1.1)}
|
||||
}
|
||||
.season-lights .season-greet{position:absolute;top:9px;height:20px;line-height:20px;padding:0 9px;border-radius:10px;font:600 12px/20px system-ui,-apple-system,"Segoe UI",Roboto,"Noto Sans","Noto Sans Hebrew","Noto Sans Arabic","Noto Sans Devanagari","Noto Sans CJK SC",sans-serif;white-space:nowrap;color:#1d2a33;background:rgba(255,255,255,.9);box-shadow:0 1px 4px rgba(0,0,0,.18);transition:opacity .4s}
|
||||
@media (prefers-reduced-motion:reduce){.season-lights *{animation:none!important;transition:none!important}
|
||||
}
|
||||
.season-lights.season-anchored{position:absolute;top:calc(100% - 3px);z-index:60}
|
||||
.season-prop{position:absolute;pointer-events:none}
|
||||
@media print{.season-lights,.season-prop{display:none}
|
||||
}
|
||||
@@ -65,6 +65,9 @@ type Config struct {
|
||||
// Cart turns on the shop's cart (cart: true, or cart: { page: /basket/ }):
|
||||
// HotDog's cart script, kept in the visitor's browser, for the shop pack.
|
||||
Cart *CartConfig `yaml:"cart"`
|
||||
// Seasons dresses the site for holidays through the year (seasons.go
|
||||
// in internal/seasons): `seasons: true`, or a map to say where.
|
||||
Seasons *SeasonsConfig `yaml:"seasons"`
|
||||
// Lastmod "git" dates each page by the last commit that changed its
|
||||
// source file, for the sitemap, feeds and .Lastmod, unless its front
|
||||
// matter says when it was updated. Empty: front matter dates only.
|
||||
@@ -253,6 +256,9 @@ func LoadConfig(dir string) (*Config, error) {
|
||||
if c.Cart.On() && c.Cart.Page != "" && (!strings.HasPrefix(c.Cart.Page, "/") || strings.HasPrefix(c.Cart.Page, "//")) {
|
||||
return nil, fmt.Errorf("site.yaml: cart page %q is an address on the site, starting with /", c.Cart.Page)
|
||||
}
|
||||
if err := c.Seasons.Validate(); err != nil {
|
||||
return nil, fmt.Errorf("site.yaml: seasons: %w", err)
|
||||
}
|
||||
if err := c.Analytics.Validate(); err != nil {
|
||||
return nil, fmt.Errorf("site.yaml: analytics: %w", err)
|
||||
}
|
||||
@@ -508,3 +514,63 @@ func (c *CartConfig) PagePath() string {
|
||||
}
|
||||
return c.Page
|
||||
}
|
||||
|
||||
// SeasonsConfig dresses the site for holidays through the year (`seasons:
|
||||
// true`, or a map): {{ seasons }} in the head adds the script.
|
||||
type SeasonsConfig struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
// Anchor is where the strip hangs: CSS selectors separated by " | ",
|
||||
// the first found wins. Empty: along the top of the window.
|
||||
Anchor string `yaml:"anchor"`
|
||||
// Logo is the element the day's prop is laid over: the one wrapping the
|
||||
// logo picture (not the <img> itself).
|
||||
Logo string `yaml:"logo"`
|
||||
// Art swaps a picture for the site's own drawing of it wearing the prop:
|
||||
// every picture whose address contains Image shows Art, with {prop} for
|
||||
// the prop's name.
|
||||
Art []SeasonArt `yaml:"art"`
|
||||
// Skip is a selector: pictures inside it keep their usual look.
|
||||
Skip string `yaml:"skip"`
|
||||
// Only lists the holidays to show (all of them when empty); Except, the
|
||||
// ones to leave out.
|
||||
Only []string `yaml:"only"`
|
||||
Except []string `yaml:"except"`
|
||||
// Greetings shows the day's greeting on the strip. On unless false.
|
||||
Greetings *bool `yaml:"greetings"`
|
||||
}
|
||||
|
||||
// SeasonArt is one of a site's own drawings for seasons.
|
||||
type SeasonArt struct {
|
||||
Image string `yaml:"image"`
|
||||
Art string `yaml:"art"`
|
||||
}
|
||||
|
||||
// UnmarshalYAML takes `seasons: true` as well as the map form.
|
||||
func (c *SeasonsConfig) UnmarshalYAML(n *yaml.Node) error {
|
||||
if n.Kind == yaml.ScalarNode {
|
||||
return n.Decode(&c.Enabled)
|
||||
}
|
||||
type plain SeasonsConfig
|
||||
c.Enabled = true
|
||||
return n.Decode((*plain)(c))
|
||||
}
|
||||
|
||||
// On reports whether seasons are on.
|
||||
func (c *SeasonsConfig) On() bool { return c != nil && c.Enabled }
|
||||
|
||||
// Validate checks the addresses; the holiday names are checked by the build,
|
||||
// which knows them.
|
||||
func (c *SeasonsConfig) Validate() error {
|
||||
if !c.On() {
|
||||
return nil
|
||||
}
|
||||
for _, a := range c.Art {
|
||||
if a.Image == "" {
|
||||
return fmt.Errorf("each art entry needs image: (part of the picture's address)")
|
||||
}
|
||||
if !strings.HasPrefix(a.Art, "/") || strings.HasPrefix(a.Art, "//") || !strings.Contains(a.Art, "{prop}") {
|
||||
return fmt.Errorf("art %q should be an address on the site, starting with /, with {prop} where the prop's name goes", a.Art)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
{{ with lookCSS }}<link rel="stylesheet" href="{{ . }}">{{ end }}
|
||||
{{ consent }}
|
||||
{{ cart }}
|
||||
{{ seasons }}
|
||||
<script src="{{ asset "site.js" }}"></script>
|
||||
{{ range $name, $c := .Site.Config.Collections }}{{ if $c.Feed }}{{ $path := $c.FeedPath }}{{ if not $path }}{{ $path = printf "/%s/feed.xml" $name }}{{ end }}
|
||||
<link rel="alternate" type="application/atom+xml" title="{{ $.Site.Config.Name }}: {{ $name }}" href="{{ $path }}">{{ end }}{{ end }}
|
||||
|
||||