rsrsss/xquery/opml/wikimedia.xqy

37 lines
1.3 KiB
Plaintext

import module namespace rsrsss = "https://envs.net/~lucidiot/rsrsss/rsrsss-functions" at "../functions.xqy";
declare function local:get-feeds($url as xs:anyURI, $language as xs:string) as node()* {
doc(resolve-uri('./w/index.php?title=Special:SiteMatrix', $url))//link[@rel = 'alternate'][@type = 'application/rss+xml' or @type = 'application/atom+xml']
! element outline {
attribute type { "rss" },
attribute text { @title },
attribute version { if (@type = 'application/atom+xml') then 'ATOM' else 'RSS' },
attribute xmlUrl { resolve-uri(@href, $url) },
attribute htmlUrl { $url },
(: Some languages are not actual language codes, like `wikidata` or `labs` or `wikimania2008`, so we do not include them :)
if (fn:matches($language, "\d|^\w{4,}"))
then ()
else attribute { "language" } { $language }
}
};
rsrsss:make-opml(
"Wikimedia RSS feeds",
doc('https://commons.wikimedia.org/w/api.php?action=sitematrix&format=xml')//sitematrix
! (
for $language in ./language
return <outline text="{$language/@localname}">
{
$language/site/site[not(@private)]
! local:get-feeds(@url, $language/@code)
}
</outline>,
<outline text="Specials">
{
./specials/special[not(@private)]
! local:get-feeds(@url, @lang)
}
</outline>
)
)