Badge: Advent of AI Slop [Day N] and the title of the day
Two links: the calendar, and the door of the day. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
023a39337a
commit
cd563cdfc2
3 files changed
+32
-13
No files matched your search
@@ -7,7 +7,8 @@ One small web page, made for one day of [Advent of AI Slop](https://advent-of-sl
|
|||||||
## What is here
|
## What is here
|
||||||
|
|
||||||
- `index.html` and `src/main.ts`: the page.
|
- `index.html` and `src/main.ts`: the page.
|
||||||
- `src/badge.ts`: the "Advent of AI Slop" link in the top right corner.
|
- `src/badge.ts`: the label in the top right corner, "Advent of AI Slop [Day 1] Living fishtank", which links to the
|
||||||
|
calendar and to the day.
|
||||||
- `public/preview.png`: the picture shown when the link is shared.
|
- `public/preview.png`: the picture shown when the link is shared.
|
||||||
- `.github/workflows/pages.yml`: publishes the page on GitHub Pages after every push to `main`.
|
- `.github/workflows/pages.yml`: publishes the page on GitHub Pages after every push to `main`.
|
||||||
|
|
||||||
@@ -18,7 +19,8 @@ What the page does and how it looks is free: any library, any framework, any sty
|
|||||||
Keep these in `index.html`:
|
Keep these in `index.html`:
|
||||||
|
|
||||||
- `<title>`, the description and the `og:` tags, rewritten for what was built.
|
- `<title>`, the description and the `og:` tags, rewritten for what was built.
|
||||||
- `<advent-badge day="N">` with the day this is for, and the script that loads `src/badge.ts`.
|
- `<advent-badge day="N" name="...">` with the day this is for and the title of that day, and the script that loads
|
||||||
|
`src/badge.ts`.
|
||||||
|
|
||||||
Replace `public/preview.png` with a 1200 by 630 screenshot of the finished page.
|
Replace `public/preview.png` with a 1200 by 630 screenshot of the finished page.
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -15,8 +15,8 @@
|
|||||||
<script type="module" src="./src/main.ts"></script>
|
<script type="module" src="./src/main.ts"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- day: the day of December this was made for, 1 to 24. -->
|
<!-- day: the day of December this was made for, 1 to 24. name: the title of that day. -->
|
||||||
<advent-badge day="1"></advent-badge>
|
<advent-badge day="1" name="Living fishtank"></advent-badge>
|
||||||
<main id="app"></main>
|
<main id="app"></main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
+26
-9
@@ -1,38 +1,55 @@
|
|||||||
// <advent-badge day="1">: the link in the top right corner, back to the door of the day this was made for.
|
// <advent-badge day="1" name="Living fishtank">: the label in the top right corner, "Advent of AI Slop [Day 1]
|
||||||
|
// Living fishtank". Its first part links to the calendar, the rest to the door of the day this was made for.
|
||||||
// It draws itself in a shadow root, so its styles and the page's never touch.
|
// It draws itself in a shadow root, so its styles and the page's never touch.
|
||||||
const site = 'https://advent-of-slop.quesma.com';
|
const site = 'https://advent-of-slop.quesma.com';
|
||||||
|
|
||||||
const css = `
|
const css = `
|
||||||
a {
|
nav {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
z-index: 2147483647;
|
z-index: 2147483647;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0 0.35em;
|
||||||
|
max-width: 100vw;
|
||||||
|
box-sizing: border-box;
|
||||||
padding: 0.35rem 0.7rem;
|
padding: 0.35rem 0.7rem;
|
||||||
border-bottom-left-radius: 0.5rem;
|
border-bottom-left-radius: 0.5rem;
|
||||||
background: #b8232f;
|
background: #b8232f;
|
||||||
color: #f6ecd6;
|
|
||||||
font: 700 0.8125rem/1.2 system-ui, sans-serif;
|
font: 700 0.8125rem/1.2 system-ui, sans-serif;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: #f6ecd6;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
a:hover {
|
a:hover {
|
||||||
background: #0f3b2d;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const link = (href: string, text: string): HTMLAnchorElement => {
|
||||||
|
const anchor = document.createElement('a');
|
||||||
|
anchor.href = href;
|
||||||
|
anchor.textContent = text;
|
||||||
|
return anchor;
|
||||||
|
};
|
||||||
|
|
||||||
class AdventBadge extends HTMLElement {
|
class AdventBadge extends HTMLElement {
|
||||||
connectedCallback(): void {
|
connectedCallback(): void {
|
||||||
const day = Number(this.getAttribute('day'));
|
const day = Number(this.getAttribute('day'));
|
||||||
if (!Number.isInteger(day) || day < 1 || day > 24) {
|
if (!Number.isInteger(day) || day < 1 || day > 24) {
|
||||||
throw new Error(`<advent-badge> needs day="1" to day="24", got ${this.getAttribute('day')}`);
|
throw new Error(`<advent-badge> needs day="1" to day="24", got ${this.getAttribute('day')}`);
|
||||||
}
|
}
|
||||||
|
const name = this.getAttribute('name');
|
||||||
|
if (name === null || name.trim() === '') {
|
||||||
|
throw new Error('<advent-badge> needs name="...", the title of its day, such as name="Living fishtank"');
|
||||||
|
}
|
||||||
const style = document.createElement('style');
|
const style = document.createElement('style');
|
||||||
style.textContent = css;
|
style.textContent = css;
|
||||||
const link = document.createElement('a');
|
const label = document.createElement('nav');
|
||||||
link.href = `${site}/day/${day}/`;
|
label.append(link(`${site}/`, 'Advent of AI Slop'), link(`${site}/day/${day}/`, `[Day ${day}] ${name}`));
|
||||||
link.textContent = 'Advent of AI Slop';
|
this.attachShadow({ mode: 'open' }).append(style, label);
|
||||||
link.title = `Made for day ${day} of Advent of AI Slop`;
|
|
||||||
this.attachShadow({ mode: 'open' }).append(style, link);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user