Skip to content

Commit

Permalink
more template whack-a-mole
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Oct 16, 2023
1 parent 19e059a commit 8a87a33
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 20 deletions.
4 changes: 2 additions & 2 deletions scratch.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import wtf from './src/index.js'
console.log('start')

let str = `before {{Vgrtbl|NA|1989-03-12|EU|August 16, 2008}} after
let str = `before {{literal translation|a|b}} after
`

let doc = wtf(str)
// const doc = await wtf.fetch('https://en.wikivoyage.org/wiki/Interstate_5')

console.log(doc.template().json())
// console.log(doc.template().json())
console.log(doc.text())
4 changes: 4 additions & 0 deletions src/template/custom/aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ let aliases = {
under: 'underline',
brackets: 'bracket',
raise: 'lower',
'born-in': 'born in',
'c.': 'circa',
'r.': 'reign',
}

//multiple aliases
Expand Down Expand Up @@ -256,6 +259,7 @@ let multi = {
// https://en.wikipedia.org/wiki/Template:Ferry
'station link': ['amtk', 'cta', 'bts', 'mnrr', 'mtams', 'munis', 'njts', 'scax', 'wmata', 'rwsa'],
'video game release': ['vgrelease', 'video game release hlist', 'vgrtbl', 'vgrelease hlist', 'vgrh'],
aka: ['a.k.a.', 'also known as'],
}

// - other languages -
Expand Down
54 changes: 54 additions & 0 deletions src/template/custom/text-only/abbreviations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import parse from '../../parse/toJSON/index.js'

let shorthands = [
// {{HWV|251d}} - handel, bach
['bwv', 'BWV'],
['hwv', 'HWV'],
['d.', 'D '], //Deutsch catalogue
['aka', 'a.k.a. '],

// date abbreviations
['cf.', 'cf. '],
['fl.', 'fl. '],
['circa', 'c. '],
['born in', 'b. '],
['died-in', 'd. '],
['married-in', 'm. '],
]
// create a function for each one
let fns = shorthands.reduce((h, a) => {
let [name, out] = a
h[name] = (tmpl) => {
let { first } = parse(tmpl, ['first'])
if (first || first === 0) {
return out + (first || '')
}
return out
}
return h
}, {})

// return only the name of the template
let justNames = [
'they',
'them',
'their',
'theirs',
'themself',
'they are',
'they were',
'they have',
'they do',
'he or she',
'him or her',
'his or her',
'his or hers',
'he/she',
'him/her',
'his/her',
]
justNames.forEach((str) => {
fns[str] = str
})

export default fns
7 changes: 5 additions & 2 deletions src/template/custom/text-only/easy-inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ let zeros = [
'bigdiv',
'strikethroughdiv',
'strikethrough color',
'pbpe'//pt
'pbpe', //pt
'video game release/abbr',
'nobel abbr',
'gloss',
'gcl',
]
zeros.forEach((k) => {
templates[k] = 0
})


export default templates
5 changes: 0 additions & 5 deletions src/template/custom/text-only/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ export default {
return `(r. ${obj.start}${obj.end})`
},

circa: (tmpl) => {
let { year } = parse(tmpl, ['year'])
return year ? `c. ${year}` : 'c. '
},

// https://en.wikipedia.org/wiki/Template:Decade_link
'decade link': (tmpl) => {
let { year } = parse(tmpl, ['year'])
Expand Down
14 changes: 3 additions & 11 deletions src/template/custom/text-only/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import hardcoded from './hardcoded.js'
import easyInline from './easy-inline.js'
import shorthand from './shorthands.js'
import shorthand from './shorthand-link.js'
import functions from './functions.js'
import abbreviations from './abbreviations.js'
import moreLangs from './languages.js'
import flags from './flags.js'
import table from './table-cell.js'

export default Object.assign(
{},
hardcoded,
easyInline,
shorthand,
functions,
moreLangs,
flags,
table,
)
export default Object.assign({}, hardcoded, easyInline, shorthand, functions, moreLangs, abbreviations, flags, table)
File renamed without changes.

0 comments on commit 8a87a33

Please sign in to comment.