Skip to content

Instantly share code, notes, and snippets.

@vermorel
Last active October 6, 2015 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vermorel/7782d98f3e884b7f649e to your computer and use it in GitHub Desktop.
Save vermorel/7782d98f3e884b7f649e to your computer and use it in GitHub Desktop.
Prints the page names of the pages on Lokad.com that contains a specific string in their original wiki markup
#----------------------------------------------------------------
# function Search-LokadWiki
# By Joannes Vermorel, Oct 2015, Lokad
#
# Print all the wiki page names that contains a specific string
# in their wiki code.
#----------------------------------------------------------------
function Search-LokadWiki()
{
param
(
[string]$pattern
);
$endpoint = "https://www.lokad.com/rest.aspx?Page="
$url = "https://www.lokad.com/sitemap.aspx"
[xml]$xml = (new-object System.Net.WebClient).DownloadString($url)
$pages = $xml.urlset | Foreach {$_.url.loc} |
Foreach { $_ -replace 'https://www.lokad.com/', '' } |
Foreach { $_ -replace '/', '.' }
if(-not (test-path variable:global:wwwlokadcache)) {
$cache = @{ "" = "" }
$pages | Foreach { [System.Tuple]::Create($_, (new-object System.Net.WebClient).DownloadString($endpoint + $_)) } |
Foreach{ $cache.Add([string]$_.Item1, [string]$_.Item2) }
Set-Variable -name "wwwlokadcache" -value $cache -Scope Global
}
$cache = Get-Variable -Name "wwwlokadcache" -Scope Global
$pages | Foreach { [System.Tuple]::Create([string]$_, [string]($cache.Value)[$_]) } |
Where { $_.Item2.Contains($pattern) } |
Foreach{ $_.Item1 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment