@@ -28,24 +28,59 @@ $Site.Files =
2828 else { Get-ChildItem - Recurse - File }
2929
3030$Site.PSScriptRoot = " $PSScriptRoot "
31+ foreach ($underbarDirectory in Get-ChildItem - Path $site.PSScriptRoot - Filter _ * - Directory) {
32+ $Site [$underbarDirectory.Name -replace ' ^_' ] = $Site [$underbarDirectory.Name ] = [Ordered ]@ {}
33+ foreach ($underbarFile in Get-ChildItem - Path $underbarDirectory - Recurse) {
34+ $relativePath = $underbarFile.FullName.Substring ($underbarDirectory.FullName.Length + 1 )
35+ $pointer = $site
36+ $hierarchy = @ ($relativePath -split ' [\\/]' )
37+ for ($index = 0 ; $index -lt ($hierarchy.Length - 1 ); $index ++ ) {
38+ $subdirectory = $hierarchy [$index ] -replace ' _'
39+ if (-not $pointer [$subdirectory ]) {
40+ $pointer [$subdirectory ] = [Ordered ]@ {}
41+ }
42+ $pointer = $pointer [$subdirectory ]
43+ }
44+
45+ $propertyName = $hierarchy [-1 ] -replace ' _'
46+ $getFile = @ {LiteralPath = $underbarFile.FullName }
47+ $fileData =
48+ switch - regex ($underbarFile.Extension ) {
49+ ' \.ps1$' { $ExecutionContext.SessionState.InvokeCommand.GetCommand ($underbarFile.FullName , ' ExternalScript' ) }
50+ ' \.(css|html|txt)$' { Get-Content @getFile }
51+ ' \.json$' { Get-Content @getFile | ConvertFrom-Json }
52+ ' \.jsonl$' { Get-Content @getFile | ConvertFrom-Json }
53+ ' \.psd1$' { Get-Content @getFile - Raw | ConvertFrom-StringData }
54+ ' \.(?>ps1xml|xml|svg)$' { (Get-Content @getFile - Raw) -as [xml ] }
55+ ' \.(?>yaml|toml)$' { Get-Content @getFile - Raw }
56+ ' \.csv$' { Import-Csv @getFile }
57+ ' \.tsv$' { Import-Csv @getFile - Delimiter " `t " }
58+ }
59+ if (-not $fileData ) { continue }
60+ $pointer [$relativePath -replace ' \.ps1$' ] = $fileData
61+ }
62+ }
3163
3264# region Common Functions and Filters
65+ # Any functions or filter file at the site root should be loaded.
3366$functionFileNames = ' functions' , ' function' , ' filters' , ' filter'
3467$functionPattern = " (?>$ ( $functionFileNames -join ' |' ) )\.ps1$"
3568$functionFiles = Get-ChildItem - Path $Site.PSScriptRoot |
3669 Where-Object Name -Match $functionPattern
3770
3871foreach ($file in $functionFiles ) {
39- # If we have a file with the name function or functions, we'll use it to set the site configuration.
72+ # If we have a file with the name function or functions,
73+ # we'll dot source it now so we can use the functions in the config
4074 . $file.FullName
4175}
4276# endregion Common Functions and Filters
4377
4478# Set an alias to buildPage.ps1
4579Set-Alias BuildPage ./ buildPage.ps1
4680
47- # If we have an event path,
48- $gitHubEvent =
81+ # If we have a github event,
82+ # save it to a variable and to the `$site`
83+ $site.GitHubEvent = $gitHubEvent =
4984 if ($env: GITHUB_EVENT_PATH ) {
5085 # all we need to do to serve it is copy it.
5186 Copy-Item $env: GITHUB_EVENT_PATH .\gitHubEvent.json
@@ -59,12 +94,15 @@ if (Test-Path 'CNAME') {
5994 $Site.CNAME = $CNAME = (Get-Content - Path ' CNAME' - Raw).Trim()
6095 $Site.RootUrl = " https://$CNAME /"
6196} elseif (
97+ # otherwise, if we are in a directory that could be a domain
6298 ($site.PSScriptRoot | Split-Path - Leaf) -like ' *.*'
6399) {
100+ # assume it _is_ the domain.
64101 $site.CNAME = $CNAME = ($site.PSScriptRoot | Split-Path - Leaf)
65102 $site.RootUrl = " https://$CNAME /"
66103}
67104
105+ # region config
68106# If we have a config.json file, it can be used to set the site configuration.
69107if (Test-Path ' config.json' ) {
70108 $siteConfig = Get-Content - Path ' config.json' - Raw | ConvertFrom-Json
@@ -98,17 +136,20 @@ if (Test-Path 'config.ps1') {
98136 # run it, and let it configure anything it chooses to.
99137 . $configScript
100138}
139+ # endregion config
101140
102141# Start the clock
103142$site [' LastBuildTime' ] = $lastBuildTime = [DateTime ]::Now
104143# region Build Files
105144
106145# Start the clock on the build process
107146$buildStart = [DateTime ]::Now
147+ Write-Host " Started Building Pages @ $buildStart "
108148# pipe every file we find to buildFile
109149$Site.Files | . buildPage
110150# and stop the clock
111151$buildEnd = [DateTime ]::Now
152+ Write-Host " Finished Building Pages @ $buildEnd ($ ( $buildEnd - $buildStart ) )"
112153
113154# endregion Build Files
114155
0 commit comments