(require 'ox-publish)
(require 'ox-rss)
;; (require 'ox-html)

(load "common.el")

;; (defun org-html-template (contents info)
;;   "Return complete document string after HTML conversion.
;; CONTENTS is the transcoded contents string.  INFO is a plist
;; holding export options."
;;   (concat
;;    (format
;;     (or (and (stringp org-html-xml-declaration)
;;              org-html-xml-declaration)
;;         (cdr (assoc (plist-get info :html-extension)
;;                     org-html-xml-declaration))
;;         (cdr (assoc "html" org-html-xml-declaration))

;;         "")
;;     (or (and org-html-coding-system
;;              (fboundp 'coding-system-get)
;;              (coding-system-get org-html-coding-system 'mime-charset))
;;         "iso-8859-1"))
;;    "\n"
;;    (plist-get info :html-doctype)
;;    "\n"
;;    (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
;;            (plist-get info :language) (plist-get info :language))
;;    "<head>\n"
;;    (org-html--build-meta-info info)
;;    (org-html--build-head info)
;;    (org-html--build-mathjax-config info)
;;    "</head>\n"
;;    "<body>\n"
;;    (let ((link-up (org-trim (plist-get info :html-link-up)))
;;          (link-home (org-trim (plist-get info :html-link-home))))
;;      (unless (and (string= link-up "") (string= link-up ""))
;;        (format org-html-home/up-format
;;                (or link-up link-home)
;;                (or link-home link-up))))
;;    ;; Preamble.
;;    (org-html--build-pre/postamble 'preamble info)
;;    ;; Document contents.
;;    (format "<%s class=\"%s\">\n"
;;            (nth 1 (assq 'content org-html-divs))
;;            (nth 2 (assq 'content org-html-divs)))
;;    ;; Document title.
;;    "<div class=\"navbar\">\n<div class=\"navbar-inner\">\n"
;;    (let ((title (plist-get info :title)))
;;      (format "<a class=\"brand\" href=\"#\">%s</a>\n" (org-export-data (or title "") info)))
;;    "</div>\n</div>\n"
;;    contents
;;    (format "")
;;    (format "</%s>\n"
;;            (nth 1 (assq 'content org-html-divs)))
;;    ;; Postamble.
;;    "<div class=\"container\">\n"
;;    (org-html--build-pre/postamble 'postamble info)
;;    "</div>\n"
;;    ;; Closing document.
;;    "</body>\n</html>"))

;; (defun org-html--tags (tags)
;;   "Format TAGS into HTML."
;;   (when tags
;;     (format "<small class=\"tag pull-right\">%s</small>"
;;             (mapconcat
;;              (lambda (tag)
;;                (format "<span class=\"%s\">%s</span>"
;;                        (concat org-html-tag-class-prefix
;;                                (org-html-fix-class-name tag))
;;                        tag))
;;              tags "&#xa0;"))))

;; (defun org-html-inner-template (contents info)
;;   "Return body of document string after HTML conversion.
;; CONTENTS is the transcoded contents string.  INFO is a plist
;; holding export options."
;;   (let ((depth (plist-get info :with-toc)))
;;     (concat
;;      (when depth
;;        (concat
;;         "<div class=\"row\">\n"
;;         "<div class=\"span3\">\n"
;;         ;; Table of contents.
;;         (when depth (org-html-toc depth info))
;;         "</div>\n"
;;         "<div class=\"span9\">\n"))
;;      ;; Document contents.
;;      contents
;;      (when depth
;;        "</div>\n</div>")
;;      ;; Footnotes section.
;;      (org-html-footnote-section info)
;;      ;; Bibliography.
;;      (org-html-bibliography))))

;; (defun org-html-toc (depth info)
;;   "Build a table of contents.
;; DEPTH is an integer specifying the depth of the table.  INFO is a
;; plist used as a communication channel.  Return the table of
;; contents as a string, or nil if it is empty."
;;   (let ((toc-entries
;;          (mapcar (lambda (headline)
;;                    (cons (org-html--format-toc-headline headline info)
;;                          (org-export-get-relative-level headline info)))
;;                  (org-export-collect-headlines info depth))))
;;     (when toc-entries (org-html--toc-text toc-entries))))

;; (defun org-html--toc-text (toc-entries)
;;   "Return innards of a table of contents, as a string.
;; TOC-ENTRIES is an alist where key is an entry title, as a string,
;; and value is its relative level, as an integer."
;;   (let* ((prev-level (1- (cdar toc-entries)))
;;          (start-level prev-level))
;;     (concat
;;      (mapconcat
;;       (lambda (entry)
;;         (let ((headline (car entry))
;;               (level (cdr entry)))
;;           (concat
;;            (let* ((cnt (- level prev-level))
;;                   (times (if (> cnt 0) (1- cnt) (- cnt)))
;;                   rtn)
;;              (setq prev-level level)
;;              (concat
;;               (org-html--make-string
;;                times (cond ((> cnt 0) "\n<ul class=\"nav nav-tabs nav-stacked\">\n<li>")
;;                            ((< cnt 0) "</li>\n</ul>\n")))
;;               (if (> cnt 0) "\n<ul class=\"nav nav-tabs nav-stacked\">\n<li class=\"nav-header\">Table of Contents</li>\n<li>" "</li>\n<li>")))
;;            headline)))
;;       toc-entries "")
;;      (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))

(setq org-publish-use-timestamps-flag nil
      org-rss-extension "rss"
      org-publish-project-alist
      '(("oni-files"
          :base-directory "./"
          :publishing-directory "_publish/"
          :recursive nil
          :base-extension "css\\|png"
          :publishing-function org-publish-attachment)
        ("org"
         :base-directory "./"
         :publishing-directory "_publish/"
         :recursive nil
         :base-extension "org"
         :publishing-function org-html-publish-to-html
         :section-numbers nil
         :table-of-contents 1
         :html-doctype "<!DOCTYPE html>"
         :html-head "<link rel=\"stylesheet\" media=\"screen\" href=\"//openfontlibrary.org/face/fantasque-sans-mono\" rel=\"stylesheet\" type=\"text/css\"/>\n<link href=\"https://ryuslash.org/org.css\" type=\"text/css\" rel=\"stylesheet\" />"
         :html-link-home "https://ryuslash.org")
        ("projects"
         :base-directory "./projects/"
         :publishing-directory "_publish/projects/"
         :recursive t
         :base-extension "org"
         :publishing-function org-html-publish-to-html
         :section-numbers nil
         :table-of-contents 1
         :html-doctype "<!DOCTYPE html>"
         :html-head "<link rel=\"stylesheet\" media=\"screen\" href=\"//openfontlibrary.org/face/fantasque-sans-mono\" rel=\"stylesheet\" type=\"text/css\"/>\n<link href=\"https://ryuslash.org/org.css\" type=\"text/css\" rel=\"stylesheet\" />"
         :html-link-home "https://ryuslash.org")))