(require 'org)
(require 'ox-publish)
(require 'ob-tangle)
(require 'ox-html)
(require 'ox-latex)

(setq org-export-use-babel t)
(org-babel-do-load-languages
 'org-babel-load-languages
 '((shell . t)))

(defun preamble-for-menu-lev1 (_plist)
  (with-temp-buffer (insert-file-contents "<LOCAL-PATH-TO-VULGO>/storie/menu.html")
                    (insert-file-contents "<LOCAL-PATH-TO-VULGO>/preamble-lev1.html")
                    (buffer-string)))

(defun preamble-for-menu-lev0 (_plist)
  (with-temp-buffer (insert-file-contents "<LOCAL-PATH-TO-VULGO>/storie/menu-lev0.html")
                    (insert-file-contents "<LOCAL-PATH-TO-VULGO>/preamble.html")
                    (buffer-string)))

(defun preamble-for-menu-lev0-eng (_plist)
  (with-temp-buffer (insert-file-contents "<LOCAL-PATH-TO-VULGO>/eng/stories/menu-lev0.html")
                    (insert-file-contents "<LOCAL-PATH-TO-VULGO>/eng/preamble.html")
                    (buffer-string)))

(defun preamble-for-menu-lev1-eng (_plist)
  (with-temp-buffer (insert-file-contents "<LOCAL-PATH-TO-VULGO>/eng/stories/menu.html")
                    (insert-file-contents "<LOCAL-PATH-TO-VULGO>/eng/preamble-lev1.html")
                    (buffer-string)))

(setq org-publish-project-alist
      '(
        ("vulgo-all" :components ("vulgo-it" "vulgo-en"))
        ("vulgo-it" :components ("vulgo-base" "vulgo-storie" "sitemap-to-menu" "vulgo-static"))
        ("vulgo-en" :components ("vulgo-base-eng" "vulgo-stories-eng" "sitemap-to-menu-eng" "vulgo-static"))
        ("vulgo-base"
         :base-directory "<LOCAL-PATH-TO-VULGO>"
         :base-extension "org"
         :publishing-directory "<EXPORT-PATH>/" ;; can be ssh with tramp
         :recursive nil
         :publishing-function org-html-publish-to-html
         :author "Agnese Trocchi"
         :email "ima@circex.org"
         :language "it"
         :section-numbers nil
         :with-toc t
         :html-head-include-default-style nil
         :html-head-include-scripts nil
         :html-preamble preamble-for-menu-lev0
         :html-postamble "<div class='footer'><ul><li><a href='privacy.html'>Privacy</a></li><li><a href='cookies.html'>Cookies</a></li><li><a href='contacts.html'>Contacts</a></li><li><a href='vulgo.html'>Vulgo</a></li><li><a href='credits.html'>Credits</a></li></ul></div>")
        ("vulgo-base-eng"
         :base-directory "<LOCAL-PATH-TO-VULGO>/eng"
         :base-extension "org"
         :publishing-directory "<EXPORT-PATH>/en/" ;; can be ssh with tramp
         :recursive nil
         :publishing-function org-html-publish-to-html
         :author "Agnese Trocchi"
         :email "ima@circex.org"
         :language "it"
         :section-numbers nil
         :with-toc t
         :html-head-include-default-style nil
         :html-head-include-scripts nil
         :html-preamble preamble-for-menu-lev0-eng
         :html-postamble "<div class='footer'><ul><li><a href='../privacy.html'>Privacy</a></li><li><a href='../cookies.html'>Cookies</a></li><li><a href='contacts.html'>Contacts</a></li><li><a href='vulgo.html'>Vulgo</a></li><li><a href='credits.html'>Credits</a></li></ul></div>")
        ("vulgo-storie"
         :base-directory "<LOCAL-PATH-TO-VULGO>/storie"
         :base-extension "org"
         :publishing-directory "<EXPORT-PATH>/storie" ;; can be ssh with tramp
         :exclude "menu.*"
         :recursive t
         :publishing-function org-html-publish-to-html
         :author "Agnese Trocchi"
         :email "ima@circex.org"
         :language "it"
         :with-toc t
         ;; Sitemap
         :auto-sitemap t
         :sitemap-title nil
         :sitemap-filename "sitemap.org"
         :html-head-include-default-style nil
         :html-head-include-scripts nil
         :html-preamble preamble-for-menu-lev1
         :html-postamble "<div class='footer'><ul><li><a href='../../privacy.html'>Privacy</a></li><li><a href='../../cookies.html'>Cookies</a></li><li><a href='../../contacts.html'>Contacts</a></li><li><a href='../../vulgo.html'>Vulgo</a></li><li><a href='../../credits.html'>Credits</a></li></ul></div>")
        ("vulgo-stories-eng"
         :base-directory "<LOCAL-PATH-TO-VULGO>/eng/stories"
         :base-extension "org"
         :publishing-directory "<EXPORT-PATH>/en/stories" ;; can be ssh with tramp
         :exclude "menu.*"
         :recursive t
         :publishing-function org-html-publish-to-html
         :author "Agnese Trocchi"
         :email "ima@circex.org"
         :language "it"
         :with-toc t
         ;; Sitemap
         :auto-sitemap t
         :sitemap-title nil
         :sitemap-filename "sitemap.org"
         :html-head-include-default-style nil
         :html-head-include-scripts nil
         :html-preamble preamble-for-menu-lev1-eng
         :html-postamble "<div class='footer'><ul><li><a href='../../../privacy.html'>Privacy</a></li><li><a href='../../../cookies.html'>Cookies</a></li><li><a href='../../contacts.html'>Contacts</a></li><li><a href='../../vulgo.html'>Vulgo</a></li><li><a href='../../credits.html'>Credits</a></li></ul></div>")
        ("sitemap-to-menu"
         :base-directory "<LOCAL-PATH-TO-VULGO>/storie/"
         :base-extension "org"
         :publishing-directory "<LOCAL-PATH-TO-VULGO>/storie/"
         :recursive nil
         :publishing-function org-html-publish-to-html
         :with-toc nil
         :with-author nil
         :with-creator nil
         :with-date	nil
         :with-drawers nil
         :with-email nil
         :with-title nil
         :html-head-include-default-style nil
         :html-head-include-scripts nil
         :html-preamble nil
         :html-postamble nil
         :html-divs nil)
        ("sitemap-to-menu-eng"
         :base-directory "<LOCAL-PATH-TO-VULGO>/eng/stories/"
         :base-extension "org"
         :publishing-directory "<LOCAL-PATH-TO-VULGO>/eng/stories/"
         :recursive nil
         :publishing-function org-html-publish-to-html
         :with-toc nil
         :with-author nil
         :with-creator nil
         :with-date	nil
         :with-drawers nil
         :with-email nil
         :with-title nil
         :html-head-include-default-style nil
         :html-head-include-scripts nil
         :html-preamble nil
         :html-postamble nil
         :html-divs nil)
        ("vulgo-static"
         :base-directory "<LOCAL-PATH-TO-VULGO>/"
         :base-extension "png\\|jpg\\|gif\\|css\\|js\\|pdf\\|mp3\\|ogg"
         :publishing-directory "<EXPORT-PATH>" ;; can be ssh with tramp
         :recursive t
         :publishing-function org-publish-attachment)))
