FlightGear wiki talk:Instant-Refs

From FlightGear wiki
Revision as of 16:23, 31 May 2014 by Hooray (talk | contribs) (→‎RX suffix: new section)
Jump to navigation Jump to search

regex / sourceforge

You're right - I just checked out the sourceforge archives, there's just a single tag that contains author/date, so regex seems like the right solution here - xpath alone won't get us very far. However, we can also just split the string using From:, < and - as delimiters to get substrings for author/date. But supporting regex seems like a good idea and should be straightforward to generalize as part of the CONFIG hash, maybe in addition to XPath expressions.--Hooray (talk) 16:12, 31 May 2014 (UTC)

RX suffix

That's kinda neat - "eval-metaprogramming", I guess - took me a few seconds to understand how this works behind the scenes. If it works this way, it's good, but I'd probably just use a nested hash, e.g. something like:

var CONFIG = {
"sourceforge.net": { 
        author: { xpath: "../../../tr/td/div/small/text()", regex:"/^From:\s(.*)</" },
        title:  { xpath: "../../../tr/td/div/div/b/a/text()", regex: "/(.*)/" },
        date:   { xpath: "../../../tr/td/div/small/text()", regex: "/(\d\d\d\d.\d\d.\d\d)/" },
        url:    { xpath: "../../../tr/td/div/div/b/a/@href", regex: "/(.*)/" }
    },
};

basically, each entry would consist of a single hash that contains two lookup-expressions, the xpath to get to the element itself, and the regex to do additional filtering. Otherwise, it's looking pretty good to me. That should be fairly future-proof and extensible then. We could in fact even add additional keys, for example one for post-processing all data, i.e. for cleaning up/escaping/transforming parsed data, or even just trimming. I really like the fact that you introduced a few tiny helper functions and that you didn't bloat the whole thing, but also that you extended the existing config hash! Overall, this is pretty cool and could save us quite some time when adding quotes to articles, and also save us from having to re-write useful postings. Thank you! --Hooray (talk) 16:23, 31 May 2014 (UTC)