1
0
mirror of https://github.com/one-among-us/data.git synced 2024-11-25 12:37:38 +08:00

[+] Calculate age

This commit is contained in:
Azalea Gui 2023-01-13 07:22:33 -05:00
parent 89e2a67b05
commit 4f53148671
No known key found for this signature in database
GPG Key ID: E289FAC0DA92DD2B
2 changed files with 10 additions and 0 deletions

View File

@ -4,9 +4,11 @@ zh_hans:
location: 地区
born: 出生
died: 逝世
age: 年龄
zh_hant:
key:
alias: 暱稱
location: 地區
born: 出生
died: 逝世
age: 年齡

View File

@ -7,6 +7,7 @@ import YAML from 'js-yaml';
import metadataParser from 'markdown-yaml-metadata-parser';
import { renderMdx } from "./mdx.js";
import moment from "moment";
const PUBLIC_DIR = "public";
@ -61,6 +62,13 @@ function buildPeopleInfoAndList() {
// Get sort key
const sortKey = info.info?.died ?? mdMeta.info?.died ?? '0'
// Add age
if (info.info && info.info.died && info.info.born)
{
try { info.info.age = Math.abs(moment(info.info.died).diff(info.info.born, 'years', false)) }
catch (e) { console.log(`Unable to calculate age for ${dirname}`) }
}
// Convert info dict to [[key, value], ...]
// And add info k-v pairs from markdown to the info object in json5
info.info = [...Object.entries(mdMeta.info ?? {}), ...Object.entries(info.info ?? {})]