Skip to content

Commit b66cff6

Browse files
author
James Brundage
committed
feat: MarkX.get_ScriptFile ( Fixes #102 )
1 parent e633dca commit b66cff6

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

‎Types/MarkX/get_ScriptFile.ps1‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<#
2+
.SYNOPSIS
3+
Gets MarkX Script Files
4+
.DESCRIPTION
5+
Gets PowerShell Script Files in a MarkX site
6+
#>
7+
8+
if ($this -is [Management.Automation.ExternalScriptInfo]) {
9+
return $this
10+
}
11+
12+
# If this does not have a cache, create one now
13+
if (-not $this.'#Cache') {
14+
$this | Add-Member NoteProperty '#Cache' ([Ordered]@{}) -Force
15+
}
16+
17+
# Why cache? Because we want to avoid re-parsing files
18+
# This can be especially useful for large sites.
19+
$notCached = [Collections.Queue]::new()
20+
21+
# Go over all files in the site
22+
foreach ($file in $this.File -match '\.ps1$') {
23+
# and skip any that are not markdown files.
24+
# if ($file.Name -notmatch $MarkdownFilePattern) { continue }
25+
26+
# If they have not yet been cached,
27+
if (-not $this.'#Cache'[$file.FullName]) {
28+
# cache them.
29+
$notCached.Enqueue($file.FullName)
30+
} else {
31+
$this.'#Cache'[$file.FullName]
32+
}
33+
}
34+
35+
foreach ($markx in $notCached.ToArray() | markx) {
36+
if ($markx.Path) {
37+
if ($this.'#site') {
38+
$markx.Site = $this.'#site'
39+
}
40+
$this.'#Cache'[$markX.Path] = $markx
41+
$this.'#Cache'[$markX.Path]
42+
} else {
43+
$null = $null
44+
}
45+
}

0 commit comments

Comments
 (0)