Add post title extraction
This commit is contained in:
parent
8053b966f5
commit
0a86cfaee6
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
EDITOR=vim
|
EDITOR=vim
|
||||||
TRANSFORM="" # '' / 'markdown'
|
TRANSFORM=('title' 'markdown') # empty or a subset of: 'title' 'markdown'
|
||||||
USER="" # WP user to create the post
|
USER="" # WP user to create the post
|
||||||
PASSWORD="" # application password generated for your WP user
|
PASSWORD="" # application password generated for your WP user
|
||||||
SERVER="" # server hostname, optionally with subdirectories
|
SERVER="" # server hostname, optionally with subdirectories
|
||||||
|
40
post.sh
40
post.sh
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
# config:
|
# config:
|
||||||
EDITOR=vim
|
EDITOR=vim
|
||||||
TRANSFORM="" # '' / 'markdown'
|
TRANSFORM=() # empty or a subset of: 'title' 'markdown'
|
||||||
USER="" # WP user to create the post
|
USER="" # WP user to create the post
|
||||||
PASSWORD="" # application password generated for your WP user
|
PASSWORD="" # application password generated for your WP user
|
||||||
SERVER="" # server hostname, optionally with subdirectories
|
SERVER="" # server hostname, optionally with subdirectories
|
||||||
@ -19,19 +19,40 @@ $EDITOR $TMPFILE || exit 1
|
|||||||
[[ -e $TMPFILE ]] || exit 1
|
[[ -e $TMPFILE ]] || exit 1
|
||||||
|
|
||||||
# transformations
|
# transformations
|
||||||
if [[ $TRANSFORM -eq "markdown" ]]; then
|
cp $TMPFILE $TMPFILE.trans
|
||||||
python >$TMPFILE.trans <<EOF
|
for T in "${TRANSFORM[@]}"; do
|
||||||
import markdown2
|
if [[ "$T" == "title" ]]; then
|
||||||
print(markdown2.markdown_path('$TMPFILE'))
|
python >$TMPFILE.trans2 <<EOF
|
||||||
|
import re
|
||||||
|
with open('$TMPFILE.trans', 'r') as file:
|
||||||
|
title = ''
|
||||||
|
content = file.read()
|
||||||
|
matches = re.match('^#+ (.+)', content, flags=0)
|
||||||
|
if matches:
|
||||||
|
title = matches.group(1)
|
||||||
|
content = content[len(matches.group(0)) + 1:]
|
||||||
|
with open('$TMPFILE.title', 'w') as titlefile:
|
||||||
|
titlefile.write(title)
|
||||||
|
print(content)
|
||||||
EOF
|
EOF
|
||||||
CONTENT=`cat $TMPFILE.trans`
|
TITLE=`cat $TMPFILE.title`
|
||||||
else
|
rm $TMPFILE.title
|
||||||
CONTENT=`cat $TMPFILE`
|
mv $TMPFILE.trans2 $TMPFILE.trans
|
||||||
fi
|
elif [[ "$T" == "markdown" ]]; then
|
||||||
|
python >$TMPFILE.trans2 <<EOF
|
||||||
|
import markdown2
|
||||||
|
print(markdown2.markdown_path('$TMPFILE.trans'))
|
||||||
|
EOF
|
||||||
|
mv $TMPFILE.trans2 $TMPFILE.trans
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
CONTENT=`cat $TMPFILE.trans`
|
||||||
|
rm $TMPFILE.trans
|
||||||
|
|
||||||
echo "--- START POST ---"
|
echo "--- START POST ---"
|
||||||
echo $CONTENT
|
echo $CONTENT
|
||||||
echo "--- END POST ---"
|
echo "--- END POST ---"
|
||||||
|
echo "Title: $TITLE"
|
||||||
echo "User: $USER"
|
echo "User: $USER"
|
||||||
echo "Server: $SERVER"
|
echo "Server: $SERVER"
|
||||||
echo "Status: $STATUS"
|
echo "Status: $STATUS"
|
||||||
@ -42,6 +63,7 @@ read -p "Press enter to confirm..."
|
|||||||
|
|
||||||
# push the post!
|
# push the post!
|
||||||
curl --user "$USER:$PASSWORD" -X POST \
|
curl --user "$USER:$PASSWORD" -X POST \
|
||||||
|
--data-urlencode "title=$TITLE" \
|
||||||
--data-urlencode "content=$CONTENT" \
|
--data-urlencode "content=$CONTENT" \
|
||||||
--data-urlencode "status=$STATUS" \
|
--data-urlencode "status=$STATUS" \
|
||||||
--data-urlencode "categories=$CATEGORIES" \
|
--data-urlencode "categories=$CATEGORIES" \
|
||||||
|
Loading…
Reference in New Issue
Block a user