-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get numeric custom template? #427
Comments
hey Lester! Nice job on this - that's a very complex page. here's a working example: wtf.extend((models, templates) => {
// create a custom parser function
templates['8DE4LTeamBracket'] = (tmpl, list, parse) => {
let obj = parse(tmpl) //or do a custom regex
list.push(obj)
return 'new-text'
}
// array-syntax allows easy-labeling of parameters
templates['8DE4LTeamBracket'] = ['a', 'b', 'c']
// number-syntax for returning by param # '{{name|zero|one|two}}'
templates.baz = 0
// replace the template with a string '{{asterisk}}' -> '*'
templates.asterisk = '*'
})
;(async () => {
let resp = await wtf
.fetch('ONE_Esports/Singapore_Major/2021', {
'Accept-Encoding': 'gzip',
'User-Agent': 'your_user_agent',
domain: 'liquipedia.net',
path: 'dota2/api.php',
})
.then(function (doc) {
let s = doc.section(24)
console.log(s.templates().map((t) => t.json()))
return doc.section(24)
})
return resp
})() cheers! |
liquipedia seems like a pretty-cool wiki, if you want to put-together a plugin for it, I'd be happy to help. |
Oh, thanks so much for the example! Wow sure, I would like to get a plugin! 😍 🙌 let me know what I can help too |
Sorry, can I ask another question here?
When I try to get the HTML from
May I know why? Can't find more details because the doc still in progress |
Hi, I'm trying to get the 'Playoffs' data from this wiki page and I was able to get it using the code below.
Then, according to this template doc, I expect the response data includes all these templates
{{8DE4LTeamBracket ... }}
,{{BracketMatchSummary}}
,{{Match}}
However, all the numeric templates
{{8DE4LTeamBracket ... }}
are missing. I only got{{BracketMatchSummary}}
and{{Match}}
. So I tried to add a new template using the code below, but I got this errorAn identifier or keyword cannot immediately follow a numeric literal.
Any example I can follow to add a numeric template? Or any other better way to get the 'Playoffs' data without using the template()?
For example, just display HTML for
section(24)
, is that possible/recommended? because there's a lot of bracket template, I might not able to convert all the template into custom element/component.The text was updated successfully, but these errors were encountered: