Merge branch 'master' of gitea.esy.fun:yogsototh/her.esy.fun

This commit is contained in:
Yann Esposito (Yogsototh) 2021-10-30 12:37:36 +02:00
commit 7aa04bee54
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
14 changed files with 589 additions and 8 deletions

View file

@ -47,9 +47,11 @@ DST_PANDOC_FILES ?= $(patsubst %$(EXT),%.html, \
$(SRC_PANDOC_FILES)))
PANDOC_TEMPLATE ?= templates/post.html
PANDOC_LUA_FILTER ?= engine/links-to-html.lua
PANDOC_LUA_FILTER_IMG ?= engine/img-to-webp.lua
PANDOC_LUA_METAS ?= engine/metas.lua
MK_HTML := engine/mk-html.sh
PANDOC := $(MK_HTML) $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER)
$(DST_DIR)/%.html: $(SRC_DIR)/%.org $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(MK_HTML) $(ENV_VARS)
PANDOC := $(MK_HTML) $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(PANDOC_LUA_FILTER_IMG) $(PANDOC_LUA_METAS)
$(DST_DIR)/%.html: $(SRC_DIR)/%.org $(PANDOC_TEMPLATE) $(PANDOC_LUA_FILTER) $(PANDOC_LUA_FILTER_IMG) $(PANDOC_LUA_METAS) $(MK_HTML) $(ENV_VARS)
@mkdir -p "$(dir $@)"
$(PANDOC) "$<" "$@.tmp"
minify --mime text/html "$@.tmp" > "$@"

9
engine/img-to-webp.lua Normal file
View file

@ -0,0 +1,9 @@
-- img-to-webp.lua
function Image(el)
local fileext = el.src:match("%.[^%.]+$");
-- DEBUG -- print("LUA IMG: ", fileext);
if ( fileext == ".jpg" or fileext == ".png" or fileext == ".jpeg" ) then
el.src = el.src .. ".webp"
end
return el
end

22
engine/metas.lua Normal file
View file

@ -0,0 +1,22 @@
-- intermediate store for variables and their values
local variables = {}
--- Function called for each raw block element.
function RawBlock (raw)
-- Don't do anything unless the block contains *org* markup.
if raw.format ~= 'org' then return nil end
-- extract variable name and value
local name, value = raw.text:match '#%+(%w+):%s*(.+)$'
if name and value then
variables[name] = value
end
end
-- Add the extracted variables to the document's metadata.
function Meta (meta)
for name, value in pairs(variables) do
meta[name] = value
end
return meta
end

View file

@ -4,8 +4,10 @@ set -eu
cd "$(git rev-parse --show-toplevel)" || exit 1
template="$1"
luafilter="$2"
orgfile="$3"
htmlfile="$4"
luafilterimg="$3"
luametas="$4"
orgfile="$5"
htmlfile="$6"
tocoption=""
if grep -ie '^#+options:' "$orgfile" | grep 'toc:t'>/dev/null; then
@ -16,6 +18,8 @@ set -x
pandoc $tocoption \
--template="$template" \
--lua-filter="$luafilter" \
--lua-filter="$luafilterimg" \
--lua-filter="$luametas" \
--mathml \
--from org \
--to html5 \

View file

@ -7,10 +7,18 @@ sizeof() {
stat --format="%s" "$*"
}
convert "$src" -resize 800x800\> -quality 50 "$dst"
convert "$src" -resize 800x800\> "$dst"
before=$(sizeof $src)
after=$(sizeof $dst)
if [[ "${src:e}" == "gif" ]]; then
after=$(sizeof $dst)
else
cwebp "$dst" -quiet -o "$dst.webp"
after=$(sizeof $dst.webp)
fi
if (( before <= after )); then
cp -f "$src" "$dst"

View file

@ -24,6 +24,7 @@ pkgs.mkShell {
direnv
ghc
tmux
libwebp
# for emacs dev
ripgrep
nodePackages.http-server

View file

@ -9,6 +9,8 @@
#+LANG: en
#+OPTIONS: H:5 auto-id:t
#+STARTUP: showeverything
#+lightbk: #0f0
#+darkbk: #080
#+html_head_extra: <style>img,svg {filter: brightness(0.8) sepia(100%) hue-rotate(80deg) saturate(10); } body { font-family: "Comic Sans MS", Chalkboard, sans-serif; } </style>
#+begin_notes

View file

@ -14,6 +14,8 @@
#+lang: en
#+options: auto-id:t
#+startup: showeverything
#+lightbk: #ff0
#+darkbk: #880
#+html_head_extra: <style>
#+html_head_extra: :root { --bg: #ff0; --fg: #000; }
#+html_head_extra: img,svg {filter: contrast(0.5)sepia(100%)hue-rotate(20deg)saturate(15); }

View file

@ -0,0 +1,154 @@
;;; doom-zen-writer-theme.el --- -*- lexical-binding: t; no-byte-compile: t; -*-
;;
;; Author: Yann Esposito <https://github.com/yogsototh>
;; Created: October 24, 2021
;; Version: 1.0.0
;; Keywords: custom themes, faces
;; Homepage: https://github.com/hlissner/emacs-doom-themes
;; Package-Requires: ((emacs "25.1") (cl-lib "0.5") (doom-themes "2.2.1"))
;;
;;; Code:
(require 'doom-themes)
;;
;;; Variables
(defgroup doom-plain-theme nil
"Options for the `doom-plain' theme."
:group 'doom-themes)
(defcustom doom-plain-padded-modeline doom-themes-padded-modeline
"If non-nil, adds a 4px padding to the mode-line.
Can be an integer to determine the exact padding."
:group 'doom-plain-theme
:type '(or integer boolean))
;;
;;; Theme definition
(def-doom-theme doom-zen-writer
"Theme inspired by gko's plain."
;; name default/256/16
((bg '("#ffffff"))
(bg-alt '("#eaecea"))
(base0 '("#969896"))
(base1 '("#f1f3f5"))
(base2 '("#606666"))
(base3 '("#cccccc"))
(base4 '("#e7e7e7"))
(base5 '("#a5a8a6"))
(base6 '("#fafafa"))
(base7 '("#dfdfdf"))
(base8 '("#fafafa"))
(fg '("#969896"))
(fg-alt (doom-lighten fg 0.15))
(grey fg)
(red fg)
(blue fg)
(dark-blue fg)
(orange fg)
(green fg)
(teal fg)
(yellow fg)
(magenta fg)
(violet fg)
(cyan fg)
(dark-cyan fg)
;; face categories -- required for all themes
(highlight base2)
(vertical-bar base5)
(selection base1)
(builtin base0)
(comments base5)
(doc-comments base5)
(constants base0)
(functions fg)
(keywords fg)
(methods fg)
(operators fg)
(type fg)
(strings base0)
(variables base0)
(numbers base0)
(region base4)
(error (doom-blend fg "#ff0000" 0.4))
(warning base2)
(success green)
(vc-modified base5)
(vc-added (doom-lighten fg 0.7))
(vc-deleted base2)
;; custom categories
(-modeline-pad
(when doom-plain-padded-modeline
(if (integerp doom-plain-padded-modeline) doom-plain-padded-modeline 4)))
(modeline-bg (doom-darken bg-alt 0.15))
(modeline-bg-alt (doom-darken bg-alt 0.1))
(modeline-bg-inactive (doom-darken bg-alt 0.1))
(modeline-bg-inactive-alt bg-alt)
(modeline-fg fg)
(modeline-fg-alt (doom-darken modeline-bg-inactive 0.35)))
;;;; Base theme face overrides
((error :underline `(:style wave :color ,error))
(warning :underline `(:style wave :color ,warning))
(hl-sentence :foreground "#000000" :background bg)
((font-lock-constant-face &override) :slant 'italic)
((font-lock-comment-face &override) :slant 'italic)
((font-lock-function-name-face &override) :slant 'italic)
((font-lock-type-face &override) :slant 'italic)
(hl-line :background base8)
((line-number &override) :foreground base3)
((line-number-current-line &override) :foreground base2)
(mode-line
:background modeline-bg :foreground modeline-fg
:box (if -modeline-pad `(:line-width ,-modeline-pad :color ,modeline-bg)))
(mode-line-inactive
:background modeline-bg-inactive :foreground modeline-fg-alt
:box (if -modeline-pad `(:line-width ,-modeline-pad :color ,modeline-bg-inactive)))
(mode-line-emphasis :foreground highlight)
;;;; doom-modeline
(doom-modeline-bar :background modeline-bg)
(doom-modeline-bar-inactive :inherit 'doom-modeline-bar)
(doom-modeline-project-dir :foreground fg)
(doom-modeline-buffer-file :foreground fg)
(doom-modeline-buffer-modified :weight 'bold :foreground "#000000")
(doom-modeline-panel :inherit 'mode-line-highlight :background base3 :foreground fg)
;;;; ivy
(ivy-posframe :background bg-alt)
;;;; magit
((magit-diff-added-highlight &override) :foreground fg :background (doom-blend vc-added bg 0.3))
((magit-diff-removed &override) :foreground (doom-lighten fg 0.4) :background (doom-blend vc-deleted bg 0.1))
((magit-diff-removed-highlight &override) :foreground fg :background (doom-blend vc-deleted bg 0.22))
;;;; lsp-mode
(lsp-headerline-breadcrumb-symbols-face :foreground keywords :weight 'bold)
;;;; outline <built-in>
(outline-1 :slant 'italic :foreground fg-alt)
(outline-2 :inherit 'outline-1 :foreground base2)
(outline-3 :inherit 'outline-2)
(outline-4 :inherit 'outline-3)
(outline-5 :inherit 'outline-4)
(outline-6 :inherit 'outline-5)
(outline-7 :inherit 'outline-6)
(outline-8 :inherit 'outline-7)
;;;; org <built-in>
((org-block &override) :background bg-alt)
((org-block-begin-line &override) :foreground base5)
;;;; solaire-mode
(solaire-mode-line-face
:inherit 'mode-line
:background modeline-bg-alt
:box (if -modeline-pad `(:line-width ,-modeline-pad :color ,modeline-bg-alt)))
(solaire-mode-line-inactive-face
:inherit 'mode-line-inactive
:background modeline-bg-inactive-alt
:box (if -modeline-pad `(:line-width ,-modeline-pad :color ,modeline-bg-inactive-alt)))))
;;; doom-plain-theme.el ends here

View file

@ -0,0 +1,342 @@
#+title: iA writer clone within doom-emacs
#+description:
#+keywords: emacs org-mode
#+author: Yann Esposito
#+email: yann@esposito.host
#+date: [2021-10-24 Sun]
#+lang: en
#+options: auto-id:t
#+startup: showeverything
So I played with tweaking my emacs configuration again.
I think I made something worth to be shared.
I wanted to have the same effect than in iA writer within emacs.
And I just reached this.
So the effect I am looking to achieve can be seen in this video.
#+name: demo video
#+begin_export html
<video src="./zen-writer-demo.mov" width="100%" controls autoplay>
<a href="./zen-writer-demo.mov">zen-writer-demo video (7.2MB)</a>
</video>
#+end_export
#+begin_comment
=> ./zen-writer-demo.mov zen-writer-demo video (7.2MB)
#+end_comment
It highlight the current sentence (in black) while the rest of the text is
gray.
The main issue with the =hl-sentence= package alone is that it set a specific
face to the current sentence, but does not affect the other text in the
buffer.
In fact to make it work as I would expect, you need to make the default
color grey, and only set black for the highlighted text.
Fortunately, I have recently created a personal theme close to that.
I just created a new specific one.
Everything is mostly "gray" except the font ~hl-sentence~ which is black.
And that's it.
So to make it all work I need.
- a Gray theme,
- the package ~hl-sentence~,
- the ~writeroom~ package.
So how to achieve that yourself?
Here is how I do it.
** The zen-writer theme
:PROPERTIES:
:CUSTOM_ID: the-zen-writer-theme
:END:
Download [[./doom-zen-writer-theme.el][Doom Zen-Writer theme]].
This depend on doom-themes and here is the code of the theme.
Just put it in you =~/.doom.d/themes= directory.
** add this is your ~packages.el~
:PROPERTIES:
:CUSTOM_ID: add-this-is-your--packages-el-
:END:
#+begin_src elisp
(package! hl-sentence
:pin "86ae38d3103bd20da5485cbdd59dfbd396c45ee4")
#+end_src
** Helpers
:PROPERTIES:
:CUSTOM_ID: helpers
:END:
You probably want to be able to put you out of this writing mode.
Here is a [[file:zen-writer.el][zen-writer.el]] file that contain my keymaps and useful functions.
Put it in you =~/.doom.d/= directory and in you =config.el=
put
#+begin_src emacs-lisp
(load! "~/.doom.d/zen-writer.el")
#+end_src
And with this you should pass to zen mode with ~SPC y z z~.
To make the un-zen works.
You will need to have a ~y/auto-update-theme~ function that set your current theme.
My function change the theme depending on the time of the day or the day of
the week.
So here it is for inspiration:
#+begin_src emacs-lisp
(defun y/auto-update-theme ()
"depending on time use different theme"
;; very early => gruvbox-light, solarized-light, nord-light
(let* ((day-of-week (format-time-string "%a"))
(week-end? (or (equal "Sat" day-of-week)
(equal "Sun" day-of-week)))
(hour (nth 2 (decode-time (current-time))))
(time-to-sleep? (or (> hour 22) (< hour 7)))
(theme (cond
(time-to-sleep? 'doom-plain-dark)
(week-end? 'doom-nord-light)
((<= 7 hour 8) 'doom-gruvbox-light)
((= 9 hour) 'doom-solarized-light)
((<= 10 hour 16) 'doom-solarized-white)
((<= 17 hour 18) 'doom-gruvbox-light)
((<= 19 hour 22) 'doom-oceanic-next))))
(when (not (equal doom-theme theme))
(setq doom-theme theme)
(load-theme doom-theme t))
;; run that function again next hour
(run-at-time (format "%02d:%02d" (+ hour 1) 0) nil 'y/auto-update-theme)))
#+end_src
** Bonus
:PROPERTIES:
:CUSTOM_ID: bonus
:END:
I use Nerd Fonts and in particular the font `iMWritingDuoS` which is I
think a clone of the iAWriter font.
#+begin_src emacs-lisp
(setq doom-variable-pitch-font
(font-spec :family "iMWritingDuoS Nerd Font" :size 12))
#+end_src
I hope you find this useful.
I really like how it looks now.
** Annex
:PROPERTIES:
:CUSTOM_ID: annex
:END:
The code source used in this article.
*** zen-writer
:PROPERTIES:
:CUSTOM_ID: zen-writer
:END:
#+Name: zen-writer.el
#+begin_src emacs-lisp :tangle zen-writer.el
;;; zen-writer.el -*- lexical-binding: t; -*-
(defun y/zen ()
(interactive)
(setq doom-theme 'doom-zen-writer)
(load-theme doom-theme t)
(hl-sentence-mode +1))
(defun y/unzen ()
(interactive)
(y/auto-update-theme)
(hl-sentence-mode -1))
(defun y/zen-full ()
(interactive)
(y/zen)
(toggle-frame-fullscreen)
(doom-big-font-mode +1))
(defun y/unzen-full ()
(interactive)
(y/unzen)
(toggle-frame-fullscreen)
(doom-big-font-mode -1))
(map! :leader
(:prefix ("y z" . "Zen Writer")
:desc "Full Zen Writer" "z" #'y/zen-full
:desc "un-Full Zen Writer" "u" #'y/unzen-full
:desc "Zen Writer" "t" #'y/zen
:desc "un-Zen Writer" "q" #'y/unzen))
#+end_src
*** zen-writer doom theme
:PROPERTIES:
:CUSTOM_ID: zen-writer-doom-theme
:END:
#+begin_src emacs-lisp :tangle doom-zen-writer-theme.el
;;; doom-zen-writer-theme.el --- -*- lexical-binding: t; no-byte-compile: t; -*-
;;
;; Author: Yann Esposito <https://github.com/yogsototh>
;; Created: October 24, 2021
;; Version: 1.0.0
;; Keywords: custom themes, faces
;; Homepage: https://github.com/hlissner/emacs-doom-themes
;; Package-Requires: ((emacs "25.1") (cl-lib "0.5") (doom-themes "2.2.1"))
;;
;;; Code:
(require 'doom-themes)
;;
;;; Variables
(defgroup doom-plain-theme nil
"Options for the `doom-plain' theme."
:group 'doom-themes)
(defcustom doom-plain-padded-modeline doom-themes-padded-modeline
"If non-nil, adds a 4px padding to the mode-line.
Can be an integer to determine the exact padding."
:group 'doom-plain-theme
:type '(or integer boolean))
;;
;;; Theme definition
(def-doom-theme doom-zen-writer
"Theme inspired by gko's plain."
;; name default/256/16
((bg '("#ffffff"))
(bg-alt '("#eaecea"))
(base0 '("#969896"))
(base1 '("#f1f3f5"))
(base2 '("#606666"))
(base3 '("#cccccc"))
(base4 '("#e7e7e7"))
(base5 '("#a5a8a6"))
(base6 '("#fafafa"))
(base7 '("#dfdfdf"))
(base8 '("#fafafa"))
(fg '("#969896"))
(fg-alt (doom-lighten fg 0.15))
(grey fg)
(red fg)
(blue fg)
(dark-blue fg)
(orange fg)
(green fg)
(teal fg)
(yellow fg)
(magenta fg)
(violet fg)
(cyan fg)
(dark-cyan fg)
;; face categories -- required for all themes
(highlight base2)
(vertical-bar base5)
(selection base1)
(builtin base0)
(comments base5)
(doc-comments base5)
(constants base0)
(functions fg)
(keywords fg)
(methods fg)
(operators fg)
(type fg)
(strings base0)
(variables base0)
(numbers base0)
(region base4)
(error (doom-blend fg "#ff0000" 0.4))
(warning base2)
(success green)
(vc-modified base5)
(vc-added (doom-lighten fg 0.7))
(vc-deleted base2)
;; custom categories
(-modeline-pad
(when doom-plain-padded-modeline
(if (integerp doom-plain-padded-modeline) doom-plain-padded-modeline 4)))
(modeline-bg (doom-darken bg-alt 0.15))
(modeline-bg-alt (doom-darken bg-alt 0.1))
(modeline-bg-inactive (doom-darken bg-alt 0.1))
(modeline-bg-inactive-alt bg-alt)
(modeline-fg fg)
(modeline-fg-alt (doom-darken modeline-bg-inactive 0.35)))
;;;; Base theme face overrides
((error :underline `(:style wave :color ,error))
(warning :underline `(:style wave :color ,warning))
(hl-sentence :foreground "#000000" :background bg)
((font-lock-constant-face &override) :slant 'italic)
((font-lock-comment-face &override) :slant 'italic)
((font-lock-function-name-face &override) :slant 'italic)
((font-lock-type-face &override) :slant 'italic)
(hl-line :background base8)
((line-number &override) :foreground base3)
((line-number-current-line &override) :foreground base2)
(mode-line
:background modeline-bg :foreground modeline-fg
:box (if -modeline-pad `(:line-width ,-modeline-pad :color ,modeline-bg)))
(mode-line-inactive
:background modeline-bg-inactive :foreground modeline-fg-alt
:box (if -modeline-pad `(:line-width ,-modeline-pad :color ,modeline-bg-inactive)))
(mode-line-emphasis :foreground highlight)
;;;; doom-modeline
(doom-modeline-bar :background modeline-bg)
(doom-modeline-bar-inactive :inherit 'doom-modeline-bar)
(doom-modeline-project-dir :foreground fg)
(doom-modeline-buffer-file :foreground fg)
(doom-modeline-buffer-modified :weight 'bold :foreground "#000000")
(doom-modeline-panel :inherit 'mode-line-highlight :background base3 :foreground fg)
;;;; ivy
(ivy-posframe :background bg-alt)
;;;; magit
((magit-diff-added-highlight &override) :foreground fg :background (doom-blend vc-added bg 0.3))
((magit-diff-removed &override) :foreground (doom-lighten fg 0.4) :background (doom-blend vc-deleted bg 0.1))
((magit-diff-removed-highlight &override) :foreground fg :background (doom-blend vc-deleted bg 0.22))
;;;; lsp-mode
(lsp-headerline-breadcrumb-symbols-face :foreground keywords :weight 'bold)
;;;; outline <built-in>
(outline-1 :slant 'italic :foreground fg-alt)
(outline-2 :inherit 'outline-1 :foreground base2)
(outline-3 :inherit 'outline-2)
(outline-4 :inherit 'outline-3)
(outline-5 :inherit 'outline-4)
(outline-6 :inherit 'outline-5)
(outline-7 :inherit 'outline-6)
(outline-8 :inherit 'outline-7)
;;;; org <built-in>
((org-block &override) :background bg-alt)
((org-block-begin-line &override) :foreground base5)
;;;; solaire-mode
(solaire-mode-line-face
:inherit 'mode-line
:background modeline-bg-alt
:box (if -modeline-pad `(:line-width ,-modeline-pad :color ,modeline-bg-alt)))
(solaire-mode-line-inactive-face
:inherit 'mode-line-inactive
:background modeline-bg-inactive-alt
:box (if -modeline-pad `(:line-width ,-modeline-pad :color ,modeline-bg-inactive-alt)))))
;;; doom-zen-writer-theme.el ends here
#+end_src

View file

@ -0,0 +1,31 @@
;;; zen-writer.el -*- lexical-binding: t; -*-
(defun y/zen ()
(interactive)
(setq doom-theme 'doom-zen-writer)
(load-theme doom-theme t)
(hl-sentence-mode +1))
(defun y/unzen ()
(interactive)
(y/auto-update-theme)
(hl-sentence-mode -1))
(defun y/zen-full ()
(interactive)
(y/zen)
(toggle-frame-fullscreen)
(doom-big-font-mode +1))
(defun y/unzen-full ()
(interactive)
(y/unzen)
(toggle-frame-fullscreen)
(doom-big-font-mode -1))
(map! :leader
(:prefix ("y z" . "Zen Writer")
:desc "Full Zen Writer" "z" #'y/zen-full
:desc "un-Full Zen Writer" "u" #'y/unzen-full
:desc "Zen Writer" "t" #'y/zen
:desc "un-Zen Writer" "q" #'y/unzen))

View file

@ -7,10 +7,11 @@
<meta name="author" content="$author$">
<meta name="description" content="$description$">
<meta name="keywords" content="$keywords$">
<meta name="theme-color" content="#d84100">
<link rel="stylesheet" href="/css/y.css"/>
<link rel="alternate" type="application/rss+xml" href="/rss.xml" />
<link rel="icon" href="/favicon.ico">
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#d84100">
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#2E3440">
$header-includes$
</head>
<body>

View file

@ -7,10 +7,13 @@
<meta name="author" content="$author$">
<meta name="description" content="$description$">
<meta name="keywords" content="$keywords$">
<meta name="theme-color" content="#d84100">
<link rel="stylesheet" href="/css/y.css"/>
<link rel="alternate" type="application/rss+xml" href="/rss.xml" />
<link rel="icon" href="/favicon.ico">
<meta name="theme-color" media="(prefers-color-scheme: light)"
content=$if(lightbk)$"$lightbk$"$else$"#d84100"$endif$>
<meta name="theme-color" media="(prefers-color-scheme: dark)"
content=$if(darkbk)$"$darkbk$"$else$"#2E3440"$endif$>
$header-includes$
</head>
<body>