Compare commits
No commits in common. "d467fa4f6cac18359071e544659be2c06a264cd4" and "7af9a1b6954f53c155d09b4c40480676e2d7db3e" have entirely different histories.
d467fa4f6c
...
7af9a1b695
5 changed files with 1241 additions and 70 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
63
package.json
63
package.json
|
@ -1,33 +1,34 @@
|
||||||
{
|
{
|
||||||
"name": "astrologo",
|
"name": "astrologo",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||||
"lint": "prettier --plugin-search-dir . --check .",
|
"lint": "prettier --plugin-search-dir . --check .",
|
||||||
"format": "prettier --plugin-search-dir . --write ."
|
"format": "prettier --plugin-search-dir . --write ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "^2.0.0",
|
"@sveltejs/adapter-auto": "^2.0.0",
|
||||||
"@sveltejs/kit": "^1.20.4",
|
"@sveltejs/kit": "^1.20.4",
|
||||||
"prettier": "^2.8.0",
|
"prettier": "^2.8.0",
|
||||||
"prettier-plugin-svelte": "^2.10.1",
|
"prettier-plugin-svelte": "^2.10.1",
|
||||||
"svelte": "^4.0.5",
|
"svelte": "^4.0.5",
|
||||||
"svelte-check": "^3.4.3",
|
"svelte-check": "^3.4.3",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^5.0.0",
|
||||||
"vite": "^4.4.2"
|
"vite": "^4.4.2"
|
||||||
},
|
},
|
||||||
"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",
|
||||||
"wikibase-sdk": "^9.2.2"
|
"wikiapi": "^1.19.4",
|
||||||
}
|
"wikibase-sdk": "^9.2.2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
1189
pnpm-lock.yaml
Normal file
1189
pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load diff
|
@ -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 };
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue