Move ToS to content collection

This commit is contained in:
Bad Manners 2024-12-05 21:46:09 -03:00
parent a97ea99c75
commit 776d1a0bca
11 changed files with 47 additions and 38 deletions

View file

@ -2,6 +2,9 @@
"files.associations": {
"*.css": "tailwindcss"
},
"yaml.schemas": {
"./.astro/collections/tos.schema.json": "/src/data/tos/**"
},
"[astro]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},

15
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "badmanners.xyz",
"version": "2.3.0",
"version": "2.3.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "badmanners.xyz",
"version": "2.3.0",
"version": "2.3.1",
"hasInstallScript": true,
"dependencies": {
"@astrojs/alpinejs": "^0.4.0",
@ -16,12 +16,13 @@
"@types/alpinejs": "^3.13.10",
"alpinejs": "^3.14.1",
"astro": "^5.0.1",
"astro-htaccess": "^0.2.2",
"astro-htaccess": "^0.2.3",
"date-fns": "^3.6.0",
"tailwindcss": "^3.4.11",
"tippy.js": "^6.3.7",
"toml": "^3.0.0",
"typescript": "^5.6.2"
"typescript": "^5.6.2",
"yaml": "^2.6.1"
},
"devDependencies": {
"@types/node": "^22.10.1",
@ -2005,9 +2006,9 @@
}
},
"node_modules/astro-htaccess": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/astro-htaccess/-/astro-htaccess-0.2.2.tgz",
"integrity": "sha512-xBtEQIhK5NzQ72YKfpPkzfTYvXz4SNDi1+SmHXObvfsEN5MS/FeWQCcnIYb+f0KrGAr5DVtV0VOTu3sLQZsM5Q==",
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/astro-htaccess/-/astro-htaccess-0.2.3.tgz",
"integrity": "sha512-9Rraech/5sZi+3V7SsPdhNzoVdh4iLN/nQ0RACylqPs1+s6k025MKnYHuO7AUjXD0gD9iZcpDX/N3r54N15Zeg==",
"license": "MIT",
"peerDependencies": {
"astro": ">= 4.0.0 < 6"

View file

@ -1,7 +1,7 @@
{
"name": "badmanners.xyz",
"type": "module",
"version": "2.3.0",
"version": "2.3.1",
"scripts": {
"postinstall": "astro sync",
"dev": "astro dev",
@ -21,12 +21,13 @@
"@types/alpinejs": "^3.13.10",
"alpinejs": "^3.14.1",
"astro": "^5.0.1",
"astro-htaccess": "^0.2.2",
"astro-htaccess": "^0.2.3",
"date-fns": "^3.6.0",
"tailwindcss": "^3.4.11",
"tippy.js": "^6.3.7",
"toml": "^3.0.0",
"typescript": "^5.6.2"
"typescript": "^5.6.2",
"yaml": "^2.6.1"
},
"devDependencies": {
"@types/node": "^22.10.1",

12
src/content.config.ts Normal file
View file

@ -0,0 +1,12 @@
import { defineCollection, z } from "astro:content";
import { glob } from "astro/loaders";
const tos = defineCollection({
loader: glob({ pattern: "*.{yml,yaml}", base: "./src/data/tos" }),
schema: z.object({
status: z.enum(["CLOSED", "OPEN", "SEMI_OPEN", "PRIVATE"]),
updatedAt: z.date(),
}),
});
export const collections = { tos };

View file

@ -1,21 +0,0 @@
import { parse } from "date-fns";
type CommissionStatus = "CLOSED" | "OPEN" | "SEMI_OPEN" | "PRIVATE";
interface TosFeedItem {
status: CommissionStatus;
updatedAt: Date;
}
const d = (date: string) => parse(date, "yyyy-MM-dd", 0);
export const TOS_FEED: TosFeedItem[] = (
[
{ status: "CLOSED", updatedAt: d("2024-08-25") },
{ status: "OPEN", updatedAt: d("2024-07-11") },
] satisfies TosFeedItem[]
)
.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime())
.slice(0, 5);
export const { status: TOS_COMMISSION_STATUS, updatedAt: TOS_UPDATED_AT } = TOS_FEED[0];

View file

@ -0,0 +1,2 @@
updatedAt: 2024-07-11
status: OPEN

View file

@ -0,0 +1,2 @@
updatedAt: 2024-08-25
status: CLOSED

5
src/data/tos_status.ts Normal file
View file

@ -0,0 +1,5 @@
import { getCollection } from "astro:content";
export const { status: TOS_COMMISSION_STATUS, updatedAt: TOS_UPDATED_AT } = (await getCollection("tos")).sort(
(a, b) => b.data.updatedAt.getTime() - a.data.updatedAt.getTime(),
)[0].data;

View file

@ -1,7 +1,11 @@
import rss from "@astrojs/rss";
import type { APIRoute } from "astro";
import { set as dateSet, subMinutes } from "date-fns";
import { TOS_FEED } from "@data/tos";
import { getCollection } from "astro:content";
import { addHours } from "date-fns";
const TOS_FEED = (await getCollection("tos"))
.sort((a, b) => b.data.updatedAt.getTime() - a.data.updatedAt.getTime())
.slice(0, 5);
export const GET: APIRoute = ({ site }) => {
if (!site) {
@ -13,7 +17,7 @@ export const GET: APIRoute = ({ site }) => {
site,
xmlns: { atom: "http://www.w3.org/2005/Atom" },
customData: `<link href="${site}" rel="alternate" type="text/html" /><atom:link href="${new URL("feed.xml", site)}" rel="self" type="application/rss+xml" />`,
items: TOS_FEED.map(({ status, updatedAt }) => ({
items: TOS_FEED.map(({ data: { status, updatedAt } }) => ({
title: {
CLOSED: "Story commissions are closed.",
OPEN: "Story commissions are open!",
@ -21,7 +25,7 @@ export const GET: APIRoute = ({ site }) => {
PRIVATE: "Story commissions are private; they are only open to select commissioners.",
}[status],
link: new URL("terms_of_service", site).toString(),
pubDate: subMinutes(dateSet(updatedAt, { hours: 12, minutes: 0, seconds: 0 }), updatedAt.getTimezoneOffset()),
pubDate: addHours(updatedAt, 12),
})),
});
};

View file

@ -2,7 +2,7 @@
import BaseLayout from "@layouts/BaseLayout.astro";
import { IconSquareRSS } from "@components/icons";
import { TOS_COMMISSION_STATUS, TOS_UPDATED_AT } from "@data/tos";
import { TOS_COMMISSION_STATUS, TOS_UPDATED_AT } from "@data/tos_status";
---
<BaseLayout pageTitle="Terms of Service">
@ -20,7 +20,7 @@ import { TOS_COMMISSION_STATUS, TOS_UPDATED_AT } from "@data/tos";
<div class="my-2 flex items-center justify-end">
<p class="mr-1 text-sm font-medium italic">
Last update: <time datetime={TOS_UPDATED_AT.toISOString().slice(0, 10)}
>{TOS_UPDATED_AT.toLocaleDateString("en-US", { dateStyle: "long" })}</time
>{TOS_UPDATED_AT.toLocaleDateString("en-US", { dateStyle: "long", timeZone: "GMT" })}</time
>
</p>
<a

View file

@ -10,7 +10,7 @@ import {
IconWeasyl,
} from "@components/icons/brands";
import { TOS_COMMISSION_STATUS } from "@data/tos";
import { TOS_COMMISSION_STATUS } from "@data/tos_status";
import { SUBSCRIBESTAR_ENABLED } from "@data/subscribestar";
---