https://ja.nz
Ja0nz Blog 📖Intro
This file is written in Org Mode markup and may look funny in GitHub. But actually, this file alone is the blogging engine for https://ja.nz. It features:
- callable source blocks
- clean up and helper functions
- markdown export with Ox-Hugo
Org mode is really powerful combined with source block snippets. I may blog about this one day too.
Sidenote: I am not using Hugo for blogging anymore.
Table of contents
:export_hugo_custom_front_matter+: :id (org-entry-get (point) “export_file_name” t) :export_hugo_custom_front_matter+: :category (org-entry-get (point) “export_hugo_bundle” t) Short
This structure guarantees to return a string. It’s super useful for all kinds of functionality like algebraic type specification where a neutral value is required by design. 4,Nonempty record using proxy
const safeRecord = new Proxy(
{}, {
get: (handler: Record<PropertyKey, string>, name: PropertyKey) : string => {
handler[name] ??= ""; return handler[name];
}
}
);
Matching primitive types with 5,Array and object type detection
typeof
is simple. Switching on complex types instead can be a pain - looking at you array and object. Here are two helpers that can be deployed in some conditional type switching logic.
type DetectArray<T> = number extends keyof T ? true : false;
// use in type switching
DetectArray<string[]> // true
DetectArray<{ [k: number]: unknown }> // true
type DetectStringObj<T> = string extends keyof T ? true : false;
DetectStringObj<{ [k: string]: unknown }> // true
DetectStringObj<{ x: string }> // false, because { x: string } is a subtyped object
This mapped type is a ‘noop type’ in the sense that 6,Utility: Flatten nested types
input type === output type
. Still, but comes in handy with intersection/composed types when editing code as it flattens the given input type. As an example,
type Ugly = {id: string;} & {date: Date;}
// becomes
type Pretty = {id: string; date: Date;}
// with
type Flatten<T> = {
[K in keyof T]: T[K];
} & {};
:export_hugo_custom_front_matter+: :id (org-entry-get (point) “export_file_name” t) :export_hugo_custom_front_matter+: :category (org-entry-get (point) “export_hugo_bundle” t) Long
7,Proxies in fantasyland
Todo stub https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
meta
Asset | Description |
---|---|
https://ja.nz/7 | Location |
file:static/blog | Ref to assets |
Workbench
:export_hugo_custom_front_matter+: :timestamp ((lambda (ts) (let* ((d (date-to-time (if ts ts (format-time-string (org-time-stamp-format t))))) (f (pop d)) (s (pop d))) (* (+ (* f (math-pow 2 16)) s) 1000))) (org-entry-get (point) “CLOSED”))Just a bunch of #+CALL functions. Call with Misc
C-c C-c
Markup Guide
Link
Pic/Img
Text formattings
— This is one paragraph! — This is
two paragraphs! (One more line break in org)
—
This is
one paragraph with an \<br\>
—
I like to write bold. And sometimes italic or even underlined and even strike-through.
One note: verbatim
and squiqqly code
is both the same in markdown
Lists
- Minus sign
- Plus sign
Enumerated lists
- My favorite number
- Second guess
Definition list
- What is React
- react is bla bla… See more
Checkboxes
- [X] checked
- [ ] unchecked
Table
thead | n | o |
tbody | q | r |
or
thead | n | o |
---|---|---|
tbody | q | r |
Blocks
generic div
src (accept attr_html)
// class="highlight"
const answer = 42;
console.log("this is how we do")
quote
It shall be light - and it was light mode
example (accept attr_html)
For example: Let me show to you...
HTML Export
center
class=”org-center” <style>.org-center { margin-left: auto; margin-right: auto; text-align: center; }</style>
Citation
To teach how to live without certainty, and yet without being paralyzed by hesitation, is perhaps the chief thing that philosophy, in our age, can still do for those who study it.
— Bertrand Russell, A History of Western Philosophy
New short
(setq id (number-to-string (length (org-map-entries t "LEVEL=2" nil))))
(org-insert-heading)
(insert (format "%s,%s" id title))
(org-metaright)
(org-todo "DRAFT")
(org-insert-structure-template "description")
(org-set-property "export_file_name" id)
(insert "\n")
(previous-line)
New long
(setq id (number-to-string (length (org-map-entries t "LEVEL=2" nil))))
(org-insert-heading)
(insert (format "%s,%s" id title))
(org-metaright)
(org-todo "TODO")
(org-insert-structure-template "description")
(org-set-property "export_file_name" id)
(insert "\n")
(next-line)
(insert "\n")
;; Begin meta table
(org-insert-heading)
(insert "meta :noexport:")
(org-metaright)
(insert "\n")
(org-table-create "2x2")
(org-cycle)
(insert "Asset")
(org-cycle)
(insert "Description")
(org-cycle)
(insert (format "%s/%s" url id))
(org-cycle)
(insert "Location")
(org-cycle)
(insert "file:static/blog ")
(org-cycle)
(insert "Ref to assets")
(org-cycle)
(kill-whole-line)
(previous-line 6)
;; End meta table