Compare commits
2 commits
7af9a1b695
...
d467fa4f6c
Author | SHA1 | Date | |
---|---|---|---|
d467fa4f6c | |||
a38e816152 |
5 changed files with 70 additions and 1241 deletions
BIN
bun.lockb
Executable file
BIN
bun.lockb
Executable file
Binary file not shown.
63
package.json
63
package.json
|
@ -1,34 +1,33 @@
|
|||
{
|
||||
"name": "astrologo",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"lint": "prettier --plugin-search-dir . --check .",
|
||||
"format": "prettier --plugin-search-dir . --write ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "^2.0.0",
|
||||
"@sveltejs/kit": "^1.20.4",
|
||||
"prettier": "^2.8.0",
|
||||
"prettier-plugin-svelte": "^2.10.1",
|
||||
"svelte": "^4.0.5",
|
||||
"svelte-check": "^3.4.3",
|
||||
"tslib": "^2.4.1",
|
||||
"typescript": "^5.0.0",
|
||||
"vite": "^4.4.2"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"bulma": "^0.9.4",
|
||||
"date-fns": "^2.30.0",
|
||||
"erina-sign-teller": "^3.4.5",
|
||||
"unslugify": "^1.0.4",
|
||||
"wikiapi": "^1.19.4",
|
||||
"wikibase-sdk": "^9.2.2"
|
||||
}
|
||||
"name": "astrologo",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"lint": "prettier --plugin-search-dir . --check .",
|
||||
"format": "prettier --plugin-search-dir . --write ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "^2.0.0",
|
||||
"@sveltejs/kit": "^1.20.4",
|
||||
"prettier": "^2.8.0",
|
||||
"prettier-plugin-svelte": "^2.10.1",
|
||||
"svelte": "^4.0.5",
|
||||
"svelte-check": "^3.4.3",
|
||||
"tslib": "^2.4.1",
|
||||
"typescript": "^5.0.0",
|
||||
"vite": "^4.4.2"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"bulma": "^0.9.4",
|
||||
"dayjs": "^1.11.9",
|
||||
"erina-sign-teller": "^3.4.5",
|
||||
"unslugify": "^1.0.4",
|
||||
"wikibase-sdk": "^9.2.2"
|
||||
}
|
||||
}
|
||||
|
|
1189
pnpm-lock.yaml
1189
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
|
@ -1,24 +1,46 @@
|
|||
import { error } from '@sveltejs/kit';
|
||||
import Wikiapi from 'wikiapi';
|
||||
// import { error } from '@sveltejs/kit';
|
||||
// import Wikiapi from 'wikiapi';
|
||||
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 Entry = { name: string; birth: Birth };
|
||||
|
||||
let cache = new Map<string, Birth>();
|
||||
let cache = new Map<string, Entry>();
|
||||
|
||||
/** @type {import('./$types').PageLoad} */
|
||||
export async function load({ params }) {
|
||||
const nombre = unslugify(params.slug);
|
||||
const wiki = new Wikiapi();
|
||||
let birth: Birth;
|
||||
if (cache.has(nombre)) {
|
||||
birth = cache.get(nombre)!;
|
||||
const query = unslugify(params.slug);
|
||||
|
||||
if (cache.has(query)) {
|
||||
return cache.get(query)!;
|
||||
} else {
|
||||
const data = await wiki.data(nombre, 'P569');
|
||||
if (data.length === 0) throw error(404, 'Not found');
|
||||
const [year, month, day] = data[0];
|
||||
birth = { year, month, day };
|
||||
cache.set(nombre, birth);
|
||||
// const data = await wiki.data(query, 'P569');
|
||||
// if (data.length === 0) throw error(404, 'Not found');
|
||||
// const [year, month, day] = data[0];
|
||||
|
||||
const url = wdk.getEntitiesFromSitelinks({ titles: [query] });
|
||||
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 };
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@
|
|||
import type { Birth } from './+page.server.js';
|
||||
|
||||
export let data;
|
||||
$: birth = data.birth;
|
||||
$: detalleSigno = signo(birth);
|
||||
|
||||
const twoDigitNum = (num: number) => (num < 10 ? `0${num}` : num);
|
||||
$: detalleSigno = signo(data.birth);
|
||||
|
||||
const intl = Intl.DateTimeFormat('es', { dateStyle: 'long' });
|
||||
const formatDate = (date: Date) => intl.format(date);
|
||||
|
@ -18,11 +15,11 @@
|
|||
<section class="hero">
|
||||
<div class="hero-body">
|
||||
<p class="title">
|
||||
{data.nombre} es de {detalleSigno.sign}
|
||||
{data.name} es de {detalleSigno.sign}
|
||||
</p>
|
||||
|
||||
<p class="subtitle">
|
||||
Cumple el {formatBirth(birth)}
|
||||
Cumple el {formatBirth(data.birth)}
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
|
Loading…
Reference in a new issue