Compare commits

..

No commits in common. "d467fa4f6cac18359071e544659be2c06a264cd4" and "7af9a1b6954f53c155d09b4c40480676e2d7db3e" have entirely different histories.

5 changed files with 1241 additions and 70 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -25,9 +25,10 @@
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"bulma": "^0.9.4", "bulma": "^0.9.4",
"dayjs": "^1.11.9", "date-fns": "^2.30.0",
"erina-sign-teller": "^3.4.5", "erina-sign-teller": "^3.4.5",
"unslugify": "^1.0.4", "unslugify": "^1.0.4",
"wikiapi": "^1.19.4",
"wikibase-sdk": "^9.2.2" "wikibase-sdk": "^9.2.2"
} }
} }

1189
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,46 +1,24 @@
// import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
// import Wikiapi from 'wikiapi'; import Wikiapi from 'wikiapi';
import unslugify from 'unslugify'; import unslugify from 'unslugify';
import { WBK } from 'wikibase-sdk';
import dayjs from 'dayjs';
const wdk = WBK({
instance: 'https://www.wikidata.org',
sparqlEndpoint: 'https://query.wikidata.org/sparql'
});
// month is zero-indexed
export type Birth = { year: number; month: number; day: number }; export type Birth = { year: number; month: number; day: number };
export type Entry = { name: string; birth: Birth };
let cache = new Map<string, Entry>(); let cache = new Map<string, Birth>();
/** @type {import('./$types').PageLoad} */ /** @type {import('./$types').PageLoad} */
export async function load({ params }) { export async function load({ params }) {
const query = unslugify(params.slug); const nombre = unslugify(params.slug);
const wiki = new Wikiapi();
if (cache.has(query)) { let birth: Birth;
return cache.get(query)!; if (cache.has(nombre)) {
birth = cache.get(nombre)!;
} else { } else {
// const data = await wiki.data(query, 'P569'); const data = await wiki.data(nombre, 'P569');
// if (data.length === 0) throw error(404, 'Not found'); if (data.length === 0) throw error(404, 'Not found');
// const [year, month, day] = data[0]; const [year, month, day] = data[0];
birth = { year, month, day };
const url = wdk.getEntitiesFromSitelinks({ titles: [query] }); cache.set(nombre, birth);
const json = await fetch(url).then((res) => res.json());
let name = query;
if (json.normalized?.n) {
name = json.normalized.n.to;
}
const entity = json.entities[Object.keys(json.entities)[0]];
const birthday = dayjs(entity.claims?.P569[0]?.mainsnak?.datavalue?.value?.time);
const birth: Birth = {
year: birthday.year(),
month: birthday.month(),
day: birthday.date()
};
const entry: Entry = { name, birth };
cache.set(query, entry);
return entry;
} }
return { nombre: nombre, birth };
} }

View file

@ -3,7 +3,10 @@
import type { Birth } from './+page.server.js'; import type { Birth } from './+page.server.js';
export let data; export let data;
$: detalleSigno = signo(data.birth); $: birth = data.birth;
$: detalleSigno = signo(birth);
const twoDigitNum = (num: number) => (num < 10 ? `0${num}` : num);
const intl = Intl.DateTimeFormat('es', { dateStyle: 'long' }); const intl = Intl.DateTimeFormat('es', { dateStyle: 'long' });
const formatDate = (date: Date) => intl.format(date); const formatDate = (date: Date) => intl.format(date);
@ -15,11 +18,11 @@
<section class="hero"> <section class="hero">
<div class="hero-body"> <div class="hero-body">
<p class="title"> <p class="title">
{data.name} es de {detalleSigno.sign} {data.nombre} es de {detalleSigno.sign}
</p> </p>
<p class="subtitle"> <p class="subtitle">
Cumple el {formatBirth(data.birth)} Cumple el {formatBirth(birth)}
</p> </p>
</div> </div>
</section> </section>