/ja.nz

✍️

Primary LanguageAstro

Ja0nz Blog 📖 https://ja.nz

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

Short

: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)

4,Nonempty record using proxy

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.
const safeRecord = new Proxy(
  {}, {
    get: (handler: Record<PropertyKey, string>, name: PropertyKey) : string => {
      handler[name] ??= ""; return handler[name];
    }
  }
);

5,Array and object type detection

Matching primitive types with 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

6,Utility: Flatten nested types

This mapped type is a ‘noop type’ in the sense that 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];
} & {};

Long

: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)

7,Proxies in fantasyland

Todo stub https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy

meta

AssetDescription
https://ja.nz/7Location
file:static/blogRef to assets

Workbench

Misc

: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 C-c C-c

Markup Guide

Link

Linktext: Jus a cat

Pic/Img

!Alttext: Jus a cat

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

  1. My favorite number
  2. Second guess

Definition list

What is React
react is bla bla… See more

Checkboxes

  • [X] checked
  • [ ] unchecked

Table

theadno
tbodyqr

or

theadno
tbodyqr

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