forked from daattali/beautiful-jekyll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateRecentPosts.ps1
30 lines (26 loc) · 1.04 KB
/
UpdateRecentPosts.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[cmdletbinding()]
param(
$path = ".\_posts\*.md"
)
$path = (Get-ChildItem $path | Sort-Object name -Descending | Select-Object -First 8).fullname
$lineTemplate = '* {0} [**{1}**](/{2}/?utm_source=blog&utm_medium=blog&utm_content=recent)'
$template = @'
---
layout: post
title: "{Title:Powershell: PSGraph, A graph module built on GraphViz}"
date: {Date:2017-01-30}
tags: [{Tags:PowerShell,PSGraph,GraphViz}]
---
'@
$output = foreach ($node in $path) {
$parsedValues = Get-Content $node -raw | ConvertFrom-String -TemplateContent $template
$tags = $parsedValues | Where-Object Tags | ForEach-Object { $_.Tags -split ',' } | ForEach-Object { $_.trim() }
$postInfo = [pscustomobject]@{
Post = (Split-Path $node -Leaf).Replace('.md', '')
Title = $parsedValues | Where-Object Title | ForEach-Object Title
Tags = $tags
Date = $parsedValues | Where-Object Date | ForEach-Object Date
}
$lineTemplate -f $postInfo.Date, $postInfo.Title, $postInfo.Post
}
$output | Set-Content -Path ".\_includes\recent-posts.md"