Skip to content

Commit 3266c14

Browse files
committed
十周年快乐🎉!
1 parent 84f265c commit 3266c14

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package friends
2+
3+
import (
4+
"embed"
5+
6+
"github.com/movsb/taoblog/modules/utils"
7+
"github.com/movsb/taoblog/modules/utils/dir"
8+
dynamic "github.com/movsb/taoblog/service/modules/renderers/_dynamic"
9+
"github.com/movsb/taoblog/theme/modules/sass"
10+
)
11+
12+
//go:generate sass --no-source-map style.scss style.css
13+
14+
//go:embed style.css script.js
15+
var _root embed.FS
16+
17+
func init() {
18+
dynamic.RegisterInit(func() {
19+
dynamic.Dynamic[`anniversary`] = dynamic.Content{
20+
Styles: []string{
21+
string(utils.Must1(_root.ReadFile(`style.css`))),
22+
},
23+
Scripts: []string{
24+
string(utils.Must1(_root.ReadFile(`script.js`))),
25+
},
26+
}
27+
sass.WatchDefaultAsync(string(dir.SourceAbsoluteDir()))
28+
})
29+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
function setupAnniversary(){
2+
3+
const date = new Date().toDateString();
4+
5+
if (!date.includes('Dec 24 2024') && !date.includes('Dec 25 2024')) {
6+
return;
7+
}
8+
9+
if (location.pathname != '/') {
10+
return;
11+
}
12+
13+
const canvas = document.createElement('canvas');
14+
canvas.classList.add('anniversary');
15+
canvas.width = window.innerWidth;
16+
canvas.height = window.innerHeight;
17+
document.body.appendChild(canvas);
18+
19+
const ctx = canvas.getContext('2d');
20+
const emojis = ['🎂', '🎄'];
21+
22+
const particles = [];
23+
24+
class Particle {
25+
constructor(x, y, emoji) {
26+
this.x = x;
27+
this.y = y;
28+
this.size = Math.random() * 40 + 20;
29+
this.speed = Math.random() + 1;
30+
this.emoji = emoji;
31+
}
32+
draw() {
33+
ctx.font = `${this.size}px Arial`;
34+
ctx.textAlign = 'center';
35+
ctx.fillText(this.emoji, this.x, this.y);
36+
}
37+
update() {
38+
this.y += this.speed;
39+
if (this.y > canvas.height) {
40+
this.y = -this.size;
41+
this.x = Math.random() * canvas.width;
42+
}
43+
}
44+
}
45+
46+
function init() {
47+
for (let i = 0; i < 30; i++) {
48+
const randomEmoji = emojis[Math.floor(Math.random() * emojis.length)];
49+
const x = Math.random() * canvas.width;
50+
const y = Math.random() * canvas.height - canvas.height;
51+
particles.push(new Particle(x, y, randomEmoji));
52+
}
53+
}
54+
55+
let timer = undefined;
56+
timer = setTimeout(function(){
57+
clearTimeout(timer);
58+
timer = undefined;
59+
}, 10000);
60+
61+
function animate() {
62+
ctx.clearRect(0, 0, canvas.width, canvas.height);
63+
particles.forEach(particle => {
64+
particle.update();
65+
particle.draw();
66+
});
67+
if (timer) {
68+
requestAnimationFrame(animate);
69+
} else {
70+
canvas.remove();
71+
}
72+
}
73+
74+
init();
75+
animate();
76+
77+
window.addEventListener('resize', () => {
78+
particles.length = 0;
79+
canvas.width = window.innerWidth;
80+
canvas.height = window.innerHeight;
81+
init();
82+
});
83+
84+
}
85+
86+
document.addEventListener('DOMContentLoaded', setupAnniversary);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
canvas.anniversary {
2+
display: block;
3+
box-sizing: border-box;
4+
position: fixed;
5+
left: 0;
6+
top: 0;
7+
width: 100%;
8+
height: 100%;
9+
z-index: -1;
10+
}

service/modules/renderers/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"go.abhg.dev/goldmark/hashtag"
1818
"golang.org/x/net/html"
1919
"golang.org/x/net/html/atom"
20+
21+
_ "github.com/movsb/taoblog/service/modules/renderers/anniversary"
2022
)
2123

2224
// 后面统一改成 Option。

0 commit comments

Comments
 (0)