Skip to content

Instantly share code, notes, and snippets.

@RichieBzzzt
Last active August 22, 2018 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichieBzzzt/7d86552a1660059cd7ab7128f47cd281 to your computer and use it in GitHub Desktop.
Save RichieBzzzt/7d86552a1660059cd7ab7128f47cd281 to your computer and use it in GitHub Desktop.
[xml]$xml = Get-Content "C:\phbx\phbx\phbx\1.xml"
$folderformarkdown = "C:\phbx\phbx\phbx\markdown4"
$xmlposts = $xml.rss.channel.Item | Where-Object {($_.creator -eq "phoenixultd") -and ($_.status -eq "publish")}
foreach ($xp in $xmlPosts)
{
$content = $xp.content.InnerText
$date = Get-Date $xp.pubDate -Format 'yyyy-MM-dd'
$tags = @()
for ($i = 0; $i -le $xp.category.Count-1; $i++)
{
$tag = $xp.category[$i].nicename -replace "\W"
$tags += $tag
}
$tagMeta = "tags = ["
foreach ($t in $tags){
$tagMeta = "$tagMeta ""$t"""
if ($t -ne $tags[-1]){
$tagMeta = $tagMeta + ","
}
}
$tagMeta = "$($tagMeta)]"
#create metadata
$meta="
+++
title = ""$($xp.title)""
date = ""$date""
draft = false
$tagMeta
+++
`n"
$title = $xp.title -replace "\W", "-"
$fileName = "$($date)-$($title).md"
$path = Join-Path $folderformarkdown $fileName
$value = "$meta $content" | Out-File $path -encoding utf8
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment