Last active
August 29, 2015 14:25
-
-
Save adammichaelwood/cd5563ef228eb79c6c63 to your computer and use it in GitHub Desktop.
Turns empty markdown links into links with URLs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/local/bin/bash | |
## You may have to change that line to specify the path to the bash interpreter you want to use. | |
## BTW, this script requires bash v4.0 or better, as it uses Associative Array | |
## Someone set us up the bomb. | |
declare -A lnks | |
## links go here | |
## WIHT writers should use these, and add more | |
## other people should use these as examples and delete these | |
lnks[operating system]="compare/platforms/operating-systems" | |
lnks[Mac]="compare/mac" | |
lnks[Linux]="compare/linux" | |
lnks[CentOS]="compare/centos" | |
lnks[Debian]="compare/debian" | |
lnks[Red Hat]="compare/red-hat" | |
lnks[web server]="compare/platforms/web-servers" | |
lnks[Apache]="compare/apache" | |
lnks[Nginx]="compare/nginx" | |
lnks[LiteSpeed]="compare/litespeed" | |
lnks[IIS]="compare/iis-7.0" | |
lnks[applications]="compare/applications" | |
lnks[blog]="compare/applications/blog" | |
lnks[CMS]="compare/applications/cms" | |
lnks[WordPress]="compare/wordpress/" | |
lnks[Drupal]="compare/drupal" | |
lnks[Joomla]="compare/joomla" | |
lnks[development]="compare/development" | |
lnks[language]="compare/development/languages" | |
lnks[framework]="compare/development/frameworks" | |
lnks[Perl]="compare/perl" | |
lnks[Ruby]="compare/ruby" | |
lnks[PHP]="compare/php" | |
lnks[Python]="compare/python" | |
lnks[SSI]="compare/ssi" | |
lnks[Rails]="compare/ruby-on-rails" | |
lnks[Ruby on Rails]="compare/ruby-on-rails" | |
lnks[Django]="compare/django" | |
lnks[Zend]="compare/zend" | |
lnks[Laravel]="compare/laravel" | |
## | |
## Change this to suit. Or, if you aren't primarily doing internal linking, get rid of it. (But you'll have to change the linkurl variable below.) | |
baseurl="http://whoishostingthis.com/" | |
mdfile="$1.md" | |
for lnk in "${!lnks[@]}" | |
do | |
emptylink="\[$lnk\]()" | |
linkurl=$baseurl"${lnks[$lnk]}" | |
filledlink="\[$lnk\]\($linkurl\)" | |
sed -i '' -e "s,$emptylink,$filledlink,g" $mdfile | |
otheranchorlink="($lnk lnk)" | |
urlparen="($linkurl)" | |
sed -i '' -e "s,$otheranchorlink,$urlparen,g" $mdfile | |
done | |
# exiting so I can provide built-in README, since there are no comment blocks in bash | |
exit | |
##README## | |
' | |
This is a quickie bash script for changing empty markdown links: | |
[Anchor text]() | |
into filled markdown links: | |
[Anchor text](http://example.com) | |
based on a list of commonly used (for you) links. | |
The list of links here is for my writing at WhoIsHostingThis.com, but you can delete those links and use it for your own site. | |
TO CREATE LIST OF LINKS | |
the list of links is an associative array called "lnks" | |
edit the list above based on the examples | |
for a bunch of internal linking, edit the baseurl below the lnk list | |
for a linking to a bunch of different domains: | |
- get rid of the baseurl | |
- include the domain names in the array values | |
- edit the linkurl variable in the for loop to remove the baseurl | |
WRITING MD FILES | |
To ways to write to-be-filled links: | |
[Canonical Anchor Text Here]() | |
or | |
[NONcanonical Anchor text](Canonical Anchor Text Here lnk) | |
notice the "lnk" within the parens, after the canonical anchor text. | |
Example: | |
I might want to talk about [WordPress]() | |
or | |
I might want to talk about [the most popular blogging software on the planet](WordPress lnk) | |
TO INSTALL | |
drop this file into your execution path | |
I keep mine in the /bin/ file for my user, but other places work to --- wherever you put your bash scripts | |
Also, I like to add a quick alias to my bash profile: | |
alias mdlnk=mdlinker.sh | |
but you do not have to do that | |
TO RUN | |
on command line, in directory of file you want to fill links of: | |
$> mdlinker.sh file-name-no-extension | |
(this assume you use the .md extension, otherwise you need to change the file and these instructions) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment