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:
parent
89e2a67b05
commit
4f53148671
@ -4,9 +4,11 @@ zh_hans:
|
||||
location: 地区
|
||||
born: 出生
|
||||
died: 逝世
|
||||
age: 年龄
|
||||
zh_hant:
|
||||
key:
|
||||
alias: 暱稱
|
||||
location: 地區
|
||||
born: 出生
|
||||
died: 逝世
|
||||
age: 年齡
|
||||
|
@ -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 ?? {})]
|
||||
|
Loading…
Reference in New Issue
Block a user