Skip to content

Instantly share code, notes, and snippets.

@kouphax
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kouphax/9807305 to your computer and use it in GitHub Desktop.
Save kouphax/9807305 to your computer and use it in GitHub Desktop.
Clojure work to reomve embedded gists and replace with code blocks

Not a big fan of the my old embedded gists in posts so lets get them outta here.

  • Find all posts (historical ones) that have gists
  • Get the raw gist content and possibly syntax type (probably via api)
  • syntax highlight that
  • replace script tags (and noscript tags) with the generated syntax highlights code in a pre tag
  • win big
  • hilary
(ns briefcase.files
(require [stasis.core :as stasis]))
(def articles
(stasis/slurp-directory "resources/content/articles" #".*\.md$"))
(defn has-gists [[path content]]
(not (nil? (re-find #"https://gist\.github\.com/" content))))
(defn extract-gists [content]
(map #(nth % 1) (re-seq #"[\"|\'](http[s]?://gist\.github\.com/\d*\.js(\?[^\'\"]*)?)[\"|\']" content)))
(defn get-one [path] (let [gisted (filter has-gists articles)]
(get (zipmap (keys gisted) (map extract-gists (vals gisted))) path)))
(map extract-gists (vals (filter has-gists articles)))
(get-one "/2011-06-21-microorms-for-dotnet-inserts-updates-deletes.md")
(def content "")
(has-gists ["" content])
(re-find #"a" "jmes")
(re-seq #"[\"|\'](http[s]?://gist\.github\.com/\d*\.js(\?[^\'\"]*)?)[\"|\']" content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment