diff --git a/.drone.yml b/.drone.yml index 4b2f371..f6ea6d9 100644 --- a/.drone.yml +++ b/.drone.yml @@ -76,7 +76,7 @@ steps: - name: "Trigger Service Update" image: ocram85/portainer-serviceupdate settings: - VERBOSE: true + #VERBOSE: true URI: "https://portainer.ocram85.com" TOKEN: from_secret: NEXT_TOKEN @@ -137,7 +137,7 @@ steps: - name: "Trigger Service Update" image: ocram85/portainer-serviceupdate settings: - VERBOSE: true + #VERBOSE: true URI: "https://portainer.ocram85.com" TOKEN: from_secret: TOKEN diff --git a/config/_default/params.toml b/config/_default/params.toml index 2c36f8b..c83a98e 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -35,7 +35,7 @@ showScrollToTop = true invertPagination = false showReadingTime = true showTableOfContents = true - showTaxonomies = false + showTaxonomies = true showWordCount = true sharingLinks = ["facebook", "twitter", "pinterest", "reddit", "linkedin", "email"] diff --git a/content/posts/psmodulebase/index.md b/content/posts/psmodulebase/index.md new file mode 100644 index 0000000..dd14edf --- /dev/null +++ b/content/posts/psmodulebase/index.md @@ -0,0 +1,119 @@ +--- +title: 'PowerShell Module Base for Config Files' +date: 2022-03-21T09:14:41+01:00 +draft: true + +categories: ['PowerShell'] +tags: ['ModuleBase', 'config'] +# lastmod: 2022-03-21T09:14:41+01:00 +# showDateUpdated: true + +# custom overrides for pages +# showDate: false +# showAuthor: false +# showWordCount: false +# showReadingTime: false +# showTableOfContents: false +# showTaxonomies: false +# showEdit: false +# sharingLinks: [null] +--- + +![note](note.jpg 'Photo by [Sigmund](https://unsplash.com/@sigmund) on [Unsplash](https://unsplash.com)') + +## 🖼️ Intro + +Sometimes you want to use a basic config file for your module. This config file should be used to define basic +settings without any user specific content. This file could be placed into your PowerShell Module folder. + +Therefore you can use the automatic variable `$MyInvocation`, especially with its properties +`$MyInvocation.MyCommand.Module.ModuleBase`. This returns the full path to your current module base folder, which +can be used to join a path for your config file. + +## 📑 `.\config.psd1` config file + +Let's assume you start a new module and you need multiple config keys to work with. So you usually create a +json or powershell data based config file: + +```powershell +{ + # Logging + OutputLevel = 'Detailed' + DefaultTarget = 'Console' + LogRetentionInWeeks = 4 + + # DataSource + CouchDBURI = 'http://localhost' + MongoDBURI = 'http://mongodb' + + # ... + # ... +} +``` + +## 🔎 `Get-ConfigValue` helper function + +Now you can use `$MyInvocation.MyCommand.Module.ModuleBase` with a helper function to parse the path to your config +file and return your needed values: + +```powershell +function Get-ConfigValue { + <# + .SYNOPSIS + Returns the value of a given config file key. + + .PARAMETER ByKey + Config file key. + + .OUTPUTS + [string] + + .EXAMPLE + Get-ConfigValue -ByKey 'OutputLevel' + + .NOTES + Private module helper function. Used by other function within your module. + #> + + [CmdletBinding()] + [OutputType([string])] + param ( + [Parameter(Mandatory = $true, HelpMessage = 'Existing key from config file.')] + [string]$ByKey + ) + + begin { } + + process { + $ModuleBase = $MyInvocation.MyCommand.Module.ModuleBase + $ConfigFile = Join-Path -Path $ModuleBase -ChildPath 'config.psd1' + + if (Test-Path -Path $ConfigFile) { + try { + $Config = Import-PowerShellDataFile -Path $ConfigFile + Write-Output $Config.$ByKey + } + catch { + Write-Error -Message $_.Exception.Message -ErrorAction Stop + } + } + else { + Write-Error -Message 'Config file not found!' -ErrorAction 'Stop' + } + } + + end { } +} +``` + +## 💭 Final Thoughts + +All you need to to is using the `Get-ConfigValue -ByKey ''` in your functions to get the any value +defined in you config file. + +As far as I know, that's the simplest way to get your module root and using it with a config file. + +{{< alert >}} +Keep in mind not to store any sensitive data in you config file. User specific data should also be stored in a user +context and not in a global module wide config. +{{< /alert >}} diff --git a/content/posts/psmodulebase/note.jpg b/content/posts/psmodulebase/note.jpg new file mode 100644 index 0000000..209076c Binary files /dev/null and b/content/posts/psmodulebase/note.jpg differ diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..54aa60d --- /dev/null +++ b/contributing.md @@ -0,0 +1,57 @@ +# Contributing to [OCram85.com](https://ocram85.com) blog + +## Usage + +To use the sources for local development you need to install the dependencies first: + +```bash +npm install +``` + +### How to add new posts + +To simplify the workflow for adding new posts you can run the npm script `new:post` with a valid path: + +```bash +npm run new:post -- posts/my-new-post/index.md +``` + +This creates a new post file an populates the values from default [template file](./archetypes/default.md) + +## npm scripts + +### `build` + +Use `npm run build` to build the html files for production. + +### `check` + +Use `npm run check` to get the current version for the embedded hugo version. + +### `clean` + +Use `npm run clean` to clean the _public_ content. + +### `lint:markdown` + +Use `npm run lint:markdown` to run the markdown linter for identifying markdown issues. + +### `start` + +Use `npm run start` as alias for `npm run server`. + +### `server` + +Use `npm run server` to start the development server which renders also draft posts. You can access the development server via `http://localhost:1313` + +### `test` + +Use `npm run test` all nested test tasks. For now this points to _lint:markdown_. + +### `postinstall` + +`npm run postinstall` is used by `npm install` to get the latest embedded hugo binary version. + +### `new:post` + +Use `npm run new:post` to create a new blog post based on the archetype template. diff --git a/package.json b/package.json index 06e49ee..4509afe 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "start": "npm run server", "server": "exec-bin node_modules/.bin/hugo/hugo server --bind=0.0.0.0 -D", "test": "npm run lint:markdown", - "postinstall": "hugo-installer --version otherDependencies.hugo --extended --destination node_modules/.bin/hugo" + "postinstall": "hugo-installer --version otherDependencies.hugo --extended --destination node_modules/.bin/hugo", + "new:post": "exec-bin node_modules/.bin/hugo/hugo new" }, "repository": { "type": "git",