Last active
October 6, 2015 18:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#---------------------------------------------------------------- | |
# 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