#+TITLE: Org Configuration

 The org configuration to generate this site.

 * Imports
 #+BEGIN_SRC emacs-lisp :results silent
   (require 'ob-css)
   (require 'ox-publish)
 #+END_SRC

 * Style

 #+NAME: style
 #+BEGIN_SRC css :results none :noweb no-export
 body {
   color: #bbb;
   background-color: #111;
   font-family: 'Palatino', serif;
   font-size: 16px;
   line-height: 24px;
   margin: 0;
   padding: 0;
 }

 a:link,
 a:visited {
   background-color: #000;
   border-bottom: solid #fff 1px;
   color: #bbb;
   padding: 0 .2em;
   text-decoration: none;
 }

 a:hover {
   background-color: #bbb;
   color: #111;
 }

 a:active {
   border-bottom: solid #f00 1px;
 }

 h1, h2, h3, h4, h5, h6 {
   color: #fff;
   font-family: 'helvetica', 'arial', sans-serif;
   font-weight: normal;
   line-height: 1.2em;
 }

 h1.title {
   border-bottom: solid #000 1px;
   padding: .2em 1em;
   margin: 0 auto;
   max-width: 696px;
   text-align: left;
 }

 #preamble {
   background-color: #000;
   height: 24px;
 }

 #preamble a:link, #preamble a:visited {
   border: none;
   display: block;
   font-family: 'helvetica', 'arial', sans-serif;
   height: 24px;
   line-height: 24px;
   max-width: 696px;
   margin: 0 auto;
   text-decoration: none;
 }

 #preamble a:active, #preamble a:hover {
   border: none;
   background-color: transparent;
   color: #f00;
 }

 #postamble {
   border-top: solid #000 1px;
   color: #999;
   font-style: italic;
   text-align: right;
   margin: 1em auto;
   padding: 0 1em;
 }

 #postamble a.source-link:link,
 #postamble a.source-link:visited {
   border-bottom: none;
   color: #ccc;
   font-family: monospace;
   font-size: .8em;
   font-style: normal;
   line-height: 24px;
   text-transform: lowercase;
   text-decoration: none;
 }

 #postamble a.source-link:hover,
 #postamble a.source-link:active {
   background-color: transparent;
   color: #0f0;
 }

 code {
   border-top: solid #000 1px;
   border-bottom: solid #000 1px;
   padding: 0 .2em;
 }

 pre.src, pre.example {
   background-color: #222;
   border-top: none;
   border-bottom: solid #000 1px;
   border-left: none;
   border-right: solid #000 1px;
   box-shadow: none;
   font-size: 14px;
   line-height: 20px;
   padding: 1em 2em;
   overflow: auto;
 }

 pre.src:before {
   background-color: transparent;
   border: none;
   top: 0;
   right: 0;
 }

 sup {
   line-height: 0;
 }

 hr {
   border-top: solid 1px #000;
   border-bottom: solid 1px #333;
 }

 li p {
   margin: 0;
 }

 .footpara {
   margin: 0;
 }

 .footnotes {
   margin-top: 1em;
 }

 h2, h3, h4, h5, h6,
 .footnotes {
   margin: 12px auto;
   max-width: 696px;
 }

 p, ul {
   margin: 12px auto;
   max-width: 672px;
 }

 li ul {
   margin-top: 0;
   margin-bottom: 0;
 }

 pre {
   margin: 0 auto;
   max-width: 672px;
 }
 #+END_SRC

 * Header
 #+NAME: header
 #+BEGIN_SRC css :results none :noweb no-export
   <style type='text/css'>
     <<style>>
   </style>
   <script>
     (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
     (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
     m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
     })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
     ga('create', 'UA-80889645-1', 'auto');
     ga('send', 'pageview');
   </script>
 #+END_SRC

 * Publishing configuration
 #+BEGIN_SRC emacs-lisp :noweb no-export :results silent
 (defun create-source-link (filename)
   (concat "./" (file-name-nondirectory filename) ".html"))

 (defun create-postamble (options)
   (let ((input-file (plist-get options :input-file)))
     (concat
      "<a class='source-link' href='"
      (create-source-link input-file)
      "'>view source</a>")))

 (defun plist-keys-helper (plist keyp counter)
   (if (and (> counter 0) (not (null plist)))
       (let ((rest (plist-keys-helper (cdr plist) (not keyp) (- counter 1))))
         (if keyp
             (cons (car plist) rest)
           rest))
     '()))

 (defun plist-keys (plist)
   (plist-keys-helper plist 't 10))

 (defun create-preamble (options)
   (if (not (string-suffix-p "src/org/index.org" (plist-get options :input-file)))
       (concat
        "<div id='#preamble'><a href='http://explog.in'>expLog</a></div>")))

 (defun create-project-configuration (title base-dir publishing-dir)
   `((,(concat title "-source")
      :base-directory ,base-dir
      :publishing-directory ,publishing-dir
      :base-extension "org"
      :recursive t
      :htmlized-source t
      :publishing-function org-org-publish-to-org)
     (,title
      :base-directory ,base-dir
      :publishing-directory ,publishing-dir
      :base-extension "org"
      :recursive t
      :section-numbers nil
      :publishing-function org-html-publish-to-html
      :with-author nil
      :with-toc nil
      :html-head-include-scripts nil
      :html-head-extra "
     <<header>>
             "
      :html-validation-link nil
      :html-footnotes-section "<div class=\"footnotes\" title=\"%s\">%s</div>"
      :html-preamble ,'create-preamble
      :html-postamble ,'create-postamble)))

 (setq
  org-publish-project-alist
  `(,@(create-project-configuration
       "explog-notes"
       "~/explog/src/org/"
       "~/explog/publish/kunalb.github.io/")
    ,@(create-project-configuration
       "dot-emacs"
       "~/dot/"
       "~/explog/publish/kunalb.github.io/dot/")
    ("explog-static"
     :base-directory "~/explog/src/static/"
     :publishing-directory "~/explog/publish/kunalb.github.io/static/"
     :base-extension any
     :recursive t
     :publishing-function org-publish-attachment)
    ("explog"
     :components ("explog-notes"
                  "explog-static"
                  "dot-emacs"
                  "explog-notes-source"
                  "dot-emacs-source"))))
 #+END_SRC

 * Publish
 #+BEGIN_SRC emacs-lisp :results silent
 (org-publish "explog" 't)
 (global-set-key
  (kbd "C-c c")
  (lambda ()
    (interactive)
    (org-babel-load-file "~/explog/src/org/config.org")))
 ; (org-babel-execute-buffer)
 #+END_SRC