Skip to content

Instantly share code, notes, and snippets.

@tinpark tinpark/p2b.sh

Last active Mar 26, 2020
Embed
What would you like to do?
p2b.sh push your file to blot, with citations rendered correctly
#!/bin/sh
# p2b.sh
# requires rsync
#
# Created by PARKER Martin on 22/05/2019.
# Modified 26/3/2020 by PARKER Martin
# This takes your markdown document, renders it to HTML and publishes it straight to blot.im
# dependencies:
# pandoc http://www.pandoc.org/
# pandoc-citeproc https://github.com/jgm/pandoc-citeproc
# a pucker .bib file (made with zotero or something) https://www.zotero.org/download/
# a bib csl style, download from here: https://www.zotero.org/styles/
# something nice to write markdown with, atom is lovely: https://atom.io/
# commandline extras
# rsync
# realpath (from coreutils on OSX)
######USAGE#######
# cd to/the/directory/with/your/markdown
# bash /path/to/script/p2b.sh inFileName.md '[catTop]/[subCat]/[subsubCat]'
# eg: bash ~/Dropbox/shellScripts/p2b.sh example.md '[teaching]/[soundtracks for screen]/[listening]'
# source file to convert to html
inputName=$1
directoryWithinBlot=$2
dropboxPath=$(cat ~/.dropbox/info.json | awk '{print $3}' | sed 's/[",]//g')
echo dropbox path is $dropboxPath
# Set the path to your blot directory, change this here if it's different
blotPath="$dropboxPath/Apps/Blot/$directoryWithinBlot"
blotRoot="$dropboxPath/Apps/Blot"
echo blot path is "$blotPath"
# set and forget these paths, tell the script where you keep your bibliography, bib style etc.
bibPath="$dropboxPath/bibliography/bibliography.bib"
cslPath="$dropboxPath/bibliography/journal-of-new-music-research.csl"
# output filename
outputName="${1%.*}.html"
# get the directory of the file that you've committed to conversion
realPath=`realpath $1`
dir="$(dirname $realPath)"
echo path of source file is "$dir"
# run pandoc script
pandoc "$inputName" --metadata link-citations=true --filter pandoc-citeproc --bibliography="$bibPath" --csl="$cslPath" -s --metadata --mathjax="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_CHTML" -o "$blotPath/$outputName"
# There is an annoyance with blot that means images are relative to the html file, so are sounds and videos, but other files are linked relative to the root of your blot directory so we sync our working directory to the place on blot that we want things to be found and then copy the files folder to the root of blot
rsync -avc --exclude '*.md' --exclude 'files' "$dir/" "$blotPath"
# here's the bit where we copy the other stuff that blot needs to see to blot's root directory
rsync -avc --exclude '*.md' --exclude 'sounds' --exclude 'videos' --exclude 'images' "$dir/" "$blotRoot"
# to do, think about setting tags from input arguments. Place them at the top of the .html document.
#tag=$4
#tags=( $tag )
#echo "First tag: '${tags[0]}'"
#echo "Second tag: '${tags[1]}'"
#echo "Third tag: '${tags[2]}'"
#echo "Number of tags in tag: '${#tags[@]}'"
# adding tags ... doesn't seem to work with blot, need to ask about that....
#echo '<!--Tags: bagels, crumpets, fishcakes-->' | cat - "$blotPath/$outputName" > temp && mv temp "$blotPath/$outputName"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.