Skip to content

Commit

Permalink
Adapt plog publishing scripts to sweet2.
Browse files Browse the repository at this point in the history
  • Loading branch information
sapegin committed Feb 18, 2016
1 parent 46e680e commit 144aace
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bin/nano-commit
Expand Up @@ -2,7 +2,7 @@

# Commits changes to blog.
#
# This script should be run from Alfred workflow.
# This script should be used from Alfred workflow.
#
# Requires:
# - terminal-notifier - brew instal terminal-notifier
Expand Down
2 changes: 1 addition & 1 deletion bin/nano-deploy
Expand Up @@ -2,7 +2,7 @@

# Deploys blog.
#
# This script should be run from Alfred workflow.
# This script should be used from Alfred workflow.
#
# Requires:
# - terminal-notifier - brew instal terminal-notifier
Expand Down
33 changes: 21 additions & 12 deletions bin/nano-post
@@ -1,20 +1,21 @@
#!/usr/bin/env bash

# Copies current opened in iA Writer Pro file to my blog’s folder, adds YAML front matter and opens it in the default editor.
# Copies current opened in iA Writer file to my blog’s folder, adds YAML front matter and opens it in Sublime Text.
#
# Files should be named like this: `SomeName_En.md`, where `En` is file’s language: En or Ru.
# Or in plain text (`Some Name`): English will be used by default.
#
# This script should be run from Alfred workflow.
# This script should be used from Alfred workflow.
#
# Author: Artem Sapegin, sapegin.me
# License: MIT
# https://github.com/sapegin/dotfiles
#

# Filepath = FILEPATH_PREFIX + language code + FILEPATH_SUFFIX + slug + FILEPATH_EXT
FILEPATH_PREFIX="$HOME/Dropbox/Projects/_Repos/blog.sapegin.me/src/documents_"
FILEPATH_PREFIX="$HOME/Dropbox/Projects/_Repos/blog.sapegin.me/source/"
FILEPATH_SUFFIX="/all/"
FILEPATH_EXT=".html.md"
FILEPATH_EXT=".md"
DATE_FORMAT="%b %e, %Y"

# Common stuff
Expand All @@ -28,18 +29,26 @@ function ask() {

# TODO: Check whether file has a name

# Topmost opened in iA Writer Pro file
source_file=$(osascript -e 'tell application "iA Writer Pro" to set filepath to file of document 1' -e 'POSIX path of filepath')
# Topmost opened in iA Writer file
source_file=$(osascript -e 'tell application "iA Writer" to set filepath to file of document 1' -e 'POSIX path of filepath')
source_name=$(basename "$source_file")

# Language
lang=$(echo "$source_name" | perl -ne 'm/_(\w\w)\.md$/; print lc $1')
if [ "$lang" != "en" ] && [ "$lang" != "ru" ]; then
error "Unknown language: $lang"
$lang="en"
fi

# Default slug: convert CamelCase file name to under_score, strip language and extension
slug=$(echo "$source_name" | perl -pe 's/([A-Z])/-\l\1/g' | perl -pe 's/^-(.*?)_-\w\w\.md/\1/')
# Default slug: convert CamelCase or plain text file name to under_score, strip language and extension
slug=$(
echo "$source_name" |
perl -pe 's/\.md$//' | # Remove extension
perl -pe 's/_(?:En|Ru)$//' | # Remove language
perl -pe 's/([A-Z])/-\l\1/g' | # CamelCase to dashes
perl -pe 's/ /-/g' | # Spaces to dashes
perl -pe 's/--/-/g' | # Remove double spaces
perl -pe 's/^-//' # Remove dash in the beginning
)

# Ask user to review the slug
slug=$(ask "Post slug:" "$slug")
Expand All @@ -62,8 +71,8 @@ title=$(grep -m 1 '#' "$source_file" | sed -e 's^# ^^')
date=$(date +"$DATE_FORMAT")

# Copy template and source file to destination folder
sed -e "s^{title}^$title^" -e "s^{date}^$date^" ~/dotfiles/bin/nano-post.tmpl > "$dest"
sed -e "s^{title}^$title^" -e "s^{date}^$date^" -e "s^{lang}^$lang^" "$HOME/dotfiles/bin/nano-post.tmpl" > "$dest"
cat "$source_file" | perl -0pe 's/#.*\n//' >> "$dest"

# Open the file in the editor
$EDITOR "$dest"
# Open the file in the editor ($EDITOR isn’t available in Alfred)
subl "$dest"
1 change: 1 addition & 0 deletions bin/nano-post.tmpl
Expand Up @@ -3,6 +3,7 @@ unpublished: true
layout: post
title: '{title}'
date: {date}
lang: {lang}
tags:
- tools
---
2 changes: 1 addition & 1 deletion bin/nano-publish
Expand Up @@ -2,7 +2,7 @@

# Publishes post to my blog: removes unpublished attribute, updates date, commits and deploys.
#
# This script should be run from Alfred workflow.
# This script should be used from Alfred workflow.
#
# Author: Artem Sapegin, sapegin.me
# License: MIT
Expand Down
4 changes: 2 additions & 2 deletions bin/nano-unpublished-for-alfred
Expand Up @@ -7,7 +7,7 @@
# https://github.com/sapegin/dotfiles
#

FILES=~/Dropbox/Projects/_Repos/blog.sapegin.me/src/documents_*/all/*.html.md
FILES=~/Dropbox/Projects/_Repos/blog.sapegin.me/source/*/all/*.md

echo '<?xml version="1.0"?><items>'

Expand All @@ -16,7 +16,7 @@ for file in $FILES; do
if grep -q 'unpublished: true' $file; then
found=1
title=$(perl -nle 'print $1 if /^title: \x27(.*?)\x27$/' "$file")
lang=$(echo "$file" | perl -nle 'print $1 if /documents_(..)/')
lang=$(perl -nle 'print $1 if /^lang: (.*?)$/' "$file")
case $lang in
ru) lang="Russian" ;;
en) lang="English" ;;
Expand Down

0 comments on commit 144aace

Please sign in to comment.