~comcloudway/pages

48db2f04833ce74fe28bfe1f3f673e2416e3a7cb — Jakob Meier 1 year, 4 months ago 8c7fbb1
Started working on the custom .org exporter
using pandoc

NOTE: this breaks a lot of my custom css,
so more work has to be done
4 files changed, 367 insertions(+), 2 deletions(-)

M build.sh
A el/gruvbox.theme
A el/html.template
M el/pub.el
M build.sh => build.sh +65 -1
@@ 1,2 1,66 @@
#!/bin/bash
yes yes | emacs --batch -l ./el/pub.el
# depends: pandoc, sed, awk

root="$(dirname $0)"
srcdir="$root/src"
assetdir="$root/res"
builddir="$root/build"

# pandoc syntax highlighting theme
pandocTheme="espresso"
# pandoc export target
pandocTarget="html5"
pandocTargetExtension="html"

# function used to convert .org file to target format
function convertOrg() {
    # read the org file as first argument
    cat "$1" | \
        # pandoc does not support elisp syntax highlighting
        # but it supports commonlisp, so we can just replace it
        sed 's/elisp/commonlisp/' | \
        pandoc \
            -f org \
            -t $pandocTarget \
            -c '/base.css' \
            --template ./el/html.template \
            --highlight-style="$pandocTheme" \
            - |
        # pandoc does not autoreplace the ->.org links,
        # so we need to autodetect them and replace the file extension,
        # with the extension of the format
        sed -r "s/([\.]+\/[A-z\/\.0-9_-]*)\.org/\1\.$pandocTargetExtension/g"
}

# delete old build artifacts
rm -rf $builddir
# create new build folder
mkdir -p $builddir

# ASSETS
cp $assetdir/* -r $builddir

prefix="s/^$(echo $srcdir | sed 's/\//\\\//')\///"

# loop through all source files
find $srcdir -type f | \
    # remove leading $srcdir
    sed "$prefix" | \
    while read file; do
        # initialise builddir path
        mkdir -p "$(dirname "$builddir/$file")"

        ext="$(echo $file | awk -F'.' '{ print $NF }')"
        if [ "$ext" = "org" ]; then
            # org files won't be called .org after conversion
            # so we need to rename them
            newName="$(echo $file | sed "s/\.org$/\.$pandocTargetExtension/")"
            echo $newName
            # me need to convert .org files
            convertOrg $srcdir/$file \
                > $builddir/$newName
        else
            # all other files can just be copied to the build dir
            cp $srcdir/$file $builddir/$file
        fi
    done

A el/gruvbox.theme => el/gruvbox.theme +226 -0
@@ 0,0 1,226 @@
{
  "metadata": {
    "author": "Jakob Meier <comcloudway@ccw.icu>",
    "license": "MIT",
    "name": "Gruvbox Pandoc theme",
    "revision": 0
  },

  "text-color": "#888888",
  "background-color": "#666666",
  "line-number-color": "#0000ff",
  "line-number-background-color": "#00ff00",

  "text-styles": {
    "Alert": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Annotation": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Attribute": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "BaseN": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "BuiltIn": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Char": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Comment": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "CommentVar": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Constant": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "ControlFlow": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "DataType": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "DecVal": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Documentation": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Error": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Extension": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Float": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Function": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Import": {
      "text-color": null,
      "background-color": null,
      "bold": null,
      "italic": true,
      "underline": false
    },
    "Information": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Keyword": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Operator": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Others": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Preprocessor": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "RegionMarker": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "SpecialChar": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "SpecialString": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "String": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Variable": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "VerbatimString": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    },
    "Warning": {
      "text-color": "#ffffff",
      "background-color": null,
      "bold": true,
      "italic": true,
      "underline": false
    }
  }
}

A el/html.template => el/html.template +70 -0
@@ 0,0 1,70 @@
<!DOCTYPE html>
<html$if(lang)$ lang="$lang$"$endif$>
  <head>
    <meta charset="utf-8">
    <meta name="generator" content="pandoc">
    $for(author-meta)$
    <meta name="author" content="$author-meta$">
    $endfor$
    $if(date-meta)$
    <meta name="dcterms.date" content="$date-meta$">
    $endif$
    <title>$if(title-prefix)$$title-prefix$ - $endif$$pagetitle$</title>
    <style type="text/css">code{white-space: pre;}</style>
         $if(quotes)$
         <style type="text/css">q { quotes: "“" "”" "‘" "’"; }</style>
         $endif$
         $if(highlighting-css)$
         <style type="text/css">
           $highlighting-css$
         </style>
         $endif$
         $for(css)$
         <link rel="stylesheet" href="$css$">
         $endfor$
         $if(math)$
         $math$
         $endif$
         $for(header-includes)$
         $header-includes$
         $endfor$
  </head>
  <body>
    $for(include-before)$
    $include-before$
    $endfor$
    $if(title)$
    <header>

      <a href="..">Up</a>

      $if(date)$
      <h3 class="date">$date$</h3>
      $endif$

      <h1 class="title">$title$</h1>


      $for(author)$
      <h2 class="author">$author.name$</h2>
      <p class="affilation"><em>$author.affiliation$</em></p>
      $endfor$

    </header>
    $endif$
    $if(toc)$
    <nav id="$idprefix$TOC">
      $toc$
    </nav>
    $endif$

    $if(abstract)$

    <p class="small"><strong>Abstract: </strong><em>$abstract$</em></p>

    $endif$


    $body$
  </body>
</html>

M el/pub.el => el/pub.el +6 -1
@@ 1,6 1,8 @@
(require 'ox-publish)

(setq package-list '(htmlize))
(global-font-lock-mode 1)

(setq package-list '(htmlize gruvbox-theme))
(package-initialize)
; fetch the list of packages available
(unless package-archive-contents


@@ 11,6 13,9 @@
  (unless (package-installed-p package)
    (package-install package)))

;;(require 'cl-lib)
;;(require 'ob-tangle)
(require 'gruvbox-theme)
(require 'htmlize)
(setq org-src-fontify-natively t)
(setq org-html-htmlize-output-type 'css-inline)