Skip to content

Instantly share code, notes, and snippets.

@staxmanade
Last active August 29, 2015 13:59
Show Gist options
  • Save staxmanade/10562366 to your computer and use it in GitHub Desktop.
Save staxmanade/10562366 to your computer and use it in GitHub Desktop.
<html dir="<$BlogLanguageDirection$>">
<head>
<title>301 Moved Permanently</title>
<noscript>
<ItemPage><Blogger><meta http-equiv="refresh" content="0,url=http://staxmanade.com/blog/<$BlogItemNumber$>"></Blogger></ItemPage>
<MainOrArchivePage><meta http-equiv="refresh" content="0,url=http://staxmanade.com"></MainOrArchivePage>
</noscript>
<script type="text/javascript">
document.location.href = '<ItemPage><Blogger>http://staxmanade.com/blog/<$BlogItemNumber$></Blogger></ItemPage><MainOrArchivePage>http://staxmanade.com</MainOrArchivePage>';
</script>
<meta name="robots" content="noindex,follow" />
<style type="text/css">#navbar-iframe {display: none;}</style>
</head>
<body>This page has moved to
<ItemPage><Blogger><a href="http://staxmanade.com/blog/<$BlogItemNumber$>">http://staxmanade.com/blog/<$BlogItemNumber$></a></Blogger></ItemPage>
<MainOrArchivePage><a href="http://staxmanade.com">staxmanade.com</a></MainOrArchivePage>
</body>
</html>
# The following script inserts Blogger/BlogSpot id's as a post
# alias into OctoPress posts (used during a migration from Blogger to BlogSpot)
#
# 1. CD into your OctoPress _posts folder
# 2. Configure the path to your exported BlogSpot/Blogger exportedPosts.xml file
# 3. Configure your Blogspot website to search/replace for.
# File path to your blogger export
$bloggerXmlFeed = "..\..\..\blog-03-19-2014.xml"
# note the trailing slash
$bloggerRootDomainUrl = 'http://staxmanade.blogspot.com/'
# Get the blogger feed as an XML object (PowerhShell is great with XML)
$xml = ([xml] (cat $bloggerXmlFeed))
# filter only 'blog posts'. We want to ignore any other types of entries.
$posts = $xml.feed.entry | where { $_.category.term -eq 'http://schemas.google.com/blogger/2008/kind#post' };
# filter only posts that were published (Ignore drafts)
$posts = $posts | ?{ !($_.control.draft -eq 'yes') }
# for each post
$posts | %{
#get the post id
$_.id | %{ $id = $_.split('-')[2] };
#get the original url slug
$url = ($_.link | where {
$_.rel -eq 'alternate'
} | %{ $_.href }).replace($bloggerRootDomainUrl, '').replace('/', '-');
# what day was the post on?
$day = "{0:00}" -f ($_.published | %{ ([datetime]$_).Day })
# calculate new path based on day
$fileName = $url.Substring(0, 7) + "-$day" + $url.Substring(7)
# validate there is a file to work with.
if(!(test-path $fileName)) {
"id - $($_.id)"
"published - $($_.published)"
Write-Error "could not find path: $fileName"
} else {
# load the file (into a variable)
$content = (Get-Content $fileName)
$delimeter = 0
$alias = "alias: /blog/$id"
# inject the 'alias into the blog's YAML at the end of the yaml heading (before the "---")
$content = $content | %{ if($_ -eq "---") { $delimeter++; }; if($delimeter -eq 2) { $alias; $delimeter++; }; $_ }
# save the modified file
Set-Content -Path $fileName -Value $content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment