added new_entry.sh script and template
new file: content/2015-11-15-migrating-from-wordpress-to-pelican.rst new file: new_entry.sh new file: template_new_entry.rst
This commit is contained in:
parent
6353ffd34b
commit
b722e82637
3 changed files with 96 additions and 0 deletions
66
content/2015-11-15-migrating-from-wordpress-to-pelican.rst
Normal file
66
content/2015-11-15-migrating-from-wordpress-to-pelican.rst
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
Migrating from WordPress to Pelican
|
||||||
|
=========================================================
|
||||||
|
|
||||||
|
:author: Russell Ballestrini
|
||||||
|
:slug: migrating-from-wordpress-to-pelican
|
||||||
|
:date: 2015-11-15 15:39
|
||||||
|
:tags: Code, DevOps
|
||||||
|
:status: published
|
||||||
|
|
||||||
|
Its finally happening. I'm moving this blog from WordPress to Pelican.
|
||||||
|
This task has lived on my TODO list for over two years.
|
||||||
|
|
||||||
|
During the process of the move, I'm going to use this post to dump hints:
|
||||||
|
|
||||||
|
.. contents:: Hints:
|
||||||
|
|
||||||
|
Good luck!
|
||||||
|
|
||||||
|
WordPress XML to JSON
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
I wrote `this tool to convert Wordpress XML dumps to JSON <https://github.com/russellballestrini/wordpress-xml-to-json>`_.
|
||||||
|
The tool is opinionated and removes lots of data.
|
||||||
|
|
||||||
|
|
||||||
|
Pelican-import
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
A tool to convert WordPress .xml into .rst or .md files (ReStructuredText or MarkDown) is
|
||||||
|
`pelican-import <http://docs.getpelican.com/en/latest/importer.html>`_.
|
||||||
|
|
||||||
|
I suggest checking it out, even if you do not plan to use Pelican as your static site generator.
|
||||||
|
|
||||||
|
Add date to post filenames
|
||||||
|
---------------------------------
|
||||||
|
|
||||||
|
After using `pelican-import <http://docs.getpelican.com/en/latest/importer.html>`_ I had about 150 `.rst` files and I decided to put the date in the filename, so I wrote this short bash script tool to do the renames
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
files=`ls *.rst`
|
||||||
|
|
||||||
|
for file in $files:
|
||||||
|
do
|
||||||
|
the_date=`grep ':date:' "$file" | awk '{ print $2; }'`
|
||||||
|
mv "$file" "$the_date-$file"
|
||||||
|
done
|
||||||
|
|
||||||
|
Alter category to tags
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
category and tags have different meanings and assumptions between wordpress and pelican. As a result I decided to change all my categories to tags using this command:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
sed -i'' -e 's/:category:/:tags:/g' *.rst
|
||||||
|
|
||||||
|
Alter attachment and image paths
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
fix paths to images / uploads to remove wp-content:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
sed -i'' -e 's/\/wp-content//g' *.rst
|
||||||
|
|
||||||
22
new_entry.sh
Normal file
22
new_entry.sh
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$1" = "" ]
|
||||||
|
then
|
||||||
|
echo "you need to pass a slug"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
THESLUG=$1
|
||||||
|
THEDATE1=`date +%Y-%m-%d`
|
||||||
|
THEDATE2=`date +"%Y-%m-%d %H:%M"`
|
||||||
|
THEFILE="content/$THEDATE1-$THESLUG.rst"
|
||||||
|
|
||||||
|
# if the entry does not exist, make a copy from template
|
||||||
|
if [ ! -f $THEFILE ];
|
||||||
|
then
|
||||||
|
cp "template_new_entry.rst" "$THEFILE"
|
||||||
|
sed -i "s/THEDATE/$THEDATE2/g" "$THEFILE"
|
||||||
|
sed -i "s/THESLUG/$THESLUG/g" "$THEFILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
vim "$THEFILE"
|
||||||
8
template_new_entry.rst
Normal file
8
template_new_entry.rst
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
THESLUG
|
||||||
|
=========================================================
|
||||||
|
|
||||||
|
:author: Russell Ballestrini
|
||||||
|
:slug: THESLUG
|
||||||
|
:date: THEDATE
|
||||||
|
:tags: Code, DevOps
|
||||||
|
:status: published
|
||||||
Loading…
Add table
Add a link
Reference in a new issue