Setup the indexer functions for the 'docs' build command
This commit is contained in:
parent
51b5c42bd4
commit
eb621760df
4
Makefile
4
Makefile
|
@ -44,11 +44,11 @@ clean:
|
||||||
|
|
||||||
.PHONY: dev-docs
|
.PHONY: dev-docs
|
||||||
dev-docs: clean
|
dev-docs: clean
|
||||||
./build.el docs
|
./build.el docs :d
|
||||||
|
|
||||||
.PHONY: docs
|
.PHONY: docs
|
||||||
docs:
|
docs:
|
||||||
FG42_PROD=true ./build.el docs
|
./build.el docs
|
||||||
|
|
||||||
serve: build
|
serve: build
|
||||||
npx http-server ./build
|
npx http-server ./build
|
||||||
|
|
6
build.el
6
build.el
|
@ -84,9 +84,9 @@ PARAMS:
|
||||||
(setq project-root (car command-line-args-left))
|
(setq project-root (car command-line-args-left))
|
||||||
|
|
||||||
(let* ((fg42-home (car command-line-args-left))
|
(let* ((fg42-home (car command-line-args-left))
|
||||||
(build-dir (from-root "/build/"))
|
(build-dir (from-root "/build"))
|
||||||
(parsed-args (read-args (cdr command-line-args-left)))
|
(parsed-args (read-args (cdr command-line-args-left)))
|
||||||
(eval-string (car parsed-args))
|
(eval-string (plist-get (car parsed-args) :e))
|
||||||
(command (caadr parsed-args))
|
(command (caadr parsed-args))
|
||||||
(args (cdadr parsed-args)))
|
(args (cdadr parsed-args)))
|
||||||
|
|
||||||
|
@ -94,6 +94,8 @@ PARAMS:
|
||||||
(when eval-string
|
(when eval-string
|
||||||
(eval (car (read-from-string eval-string))))
|
(eval (car (read-from-string eval-string))))
|
||||||
|
|
||||||
|
(setq debug-mode (plist-get (car parsed-args) :d))
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
((string= command "docs")
|
((string= command "docs")
|
||||||
(do-command
|
(do-command
|
||||||
|
|
|
@ -32,19 +32,43 @@
|
||||||
(defvar project-root nil
|
(defvar project-root nil
|
||||||
"Root directory of the website source code.")
|
"Root directory of the website source code.")
|
||||||
|
|
||||||
|
|
||||||
|
(defvar debug-mode nil)
|
||||||
|
|
||||||
|
|
||||||
(defun from-root (path)
|
(defun from-root (path)
|
||||||
"Return the full path of the given PATH in the project root."
|
"Return the full path of the given PATH in the project root."
|
||||||
(concat project-root path))
|
(concat project-root path))
|
||||||
|
|
||||||
|
|
||||||
|
(defun prod-p ()
|
||||||
|
"Return non-nil if debug mode is turned off"
|
||||||
|
(not debug-mode))
|
||||||
|
|
||||||
|
|
||||||
(defun read-args (args)
|
(defun read-args (args)
|
||||||
"Parse the give ARGS list and return a list in the following
|
"Parse the give ARGS list and return a list in the following
|
||||||
format:
|
format:
|
||||||
(EVAL_STRING (COMMAND ARGES))
|
(FLAGS (COMMAND ARGES))"
|
||||||
"
|
(seq-reduce
|
||||||
;; TODO: Because of some issues in the past we lost the original
|
(lambda (acc arg)
|
||||||
;; function and now we need to parse the ARGS for :e and :d keys
|
(let ((flags (car acc))
|
||||||
`(() ,args))
|
(commands (cadr acc))
|
||||||
|
(i (caddr acc))
|
||||||
|
(skip (cadddr acc)))
|
||||||
|
|
||||||
|
(if skip
|
||||||
|
(list flags commands (1+ i) ())
|
||||||
|
(progn
|
||||||
|
(cond
|
||||||
|
((string= arg ":d") (plist-put flags :d t))
|
||||||
|
((string= arg ":e") (progn
|
||||||
|
(plist-put flags :e (nth (1+ i) args))
|
||||||
|
(setq skip (1+ i))))
|
||||||
|
(t (push arg commands)))
|
||||||
|
(list flags commands (1+ i) skip)))))
|
||||||
|
args
|
||||||
|
'((:d () :e ()) () 0 ())))
|
||||||
|
|
||||||
|
|
||||||
(defun replace-in-buffer (str replacement)
|
(defun replace-in-buffer (str replacement)
|
||||||
|
@ -59,6 +83,7 @@ format:
|
||||||
"Replace the placeholder in SRC with list of pairs given in CONTEXT
|
"Replace the placeholder in SRC with list of pairs given in CONTEXT
|
||||||
and write it to DEST."
|
and write it to DEST."
|
||||||
(make-directory (file-name-directory dest) t)
|
(make-directory (file-name-directory dest) t)
|
||||||
|
(message "Copy template: '%s' -> '%s'" src dest)
|
||||||
(with-temp-file dest
|
(with-temp-file dest
|
||||||
(insert-file-contents src)
|
(insert-file-contents src)
|
||||||
(dolist (pair context)
|
(dolist (pair context)
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
(require 'cubes/all)
|
(require 'cubes/all)
|
||||||
(require 'fg42/build/core)
|
(require 'fg42/build/core)
|
||||||
|
(require 'fg42/build/utils)
|
||||||
|
|
||||||
|
|
||||||
(defconst cube-template (from-root "/docs/site/templates/cube.org"))
|
(defconst cube-template (from-root "/docs/site/templates/cube.org"))
|
||||||
(defconst cubes-index-template (from-root "/docs/site/templates/cubes.org"))
|
(defconst cubes-index-template (from-root "/docs/site/templates/cubes.org"))
|
||||||
|
@ -43,7 +45,6 @@
|
||||||
(docs (plist-get props :docs))
|
(docs (plist-get props :docs))
|
||||||
(cube-file (concat (expand-file-name (symbol-name cube) cubes-dir)
|
(cube-file (concat (expand-file-name (symbol-name cube) cubes-dir)
|
||||||
".org")))
|
".org")))
|
||||||
(message "Processing the docs for '%s' cube" cube)
|
|
||||||
(copy-template cube-template
|
(copy-template cube-template
|
||||||
cube-file
|
cube-file
|
||||||
(list
|
(list
|
||||||
|
@ -61,6 +62,7 @@
|
||||||
(fg42/build-docs-copy-base build-dir)
|
(fg42/build-docs-copy-base build-dir)
|
||||||
|
|
||||||
;; Build the org files for each cube
|
;; Build the org files for each cube
|
||||||
|
(message "Processing the docs for all the cubes")
|
||||||
(mapcar (lambda (cube)
|
(mapcar (lambda (cube)
|
||||||
(fg42/build-docs-for-cube build-dir cube))
|
(fg42/build-docs-for-cube build-dir cube))
|
||||||
fg42/available-cubes)
|
fg42/available-cubes)
|
||||||
|
@ -81,10 +83,40 @@
|
||||||
|
|
||||||
(defun all-org-files ()
|
(defun all-org-files ()
|
||||||
"Return a list of all the org files in the orgs directory."
|
"Return a list of all the org files in the orgs directory."
|
||||||
(mapcar #'identity
|
|
||||||
(split-string
|
(split-string
|
||||||
(shell-command-to-string (format "find %s -iname \"*.org\"" org-directory))
|
(shell-command-to-string (format "find %s -iname \"*.org\"" org-directory))
|
||||||
"\n" t)))
|
"\n" t))
|
||||||
|
|
||||||
|
|
||||||
|
(defun get-all-tags ()
|
||||||
|
"Return a list of all the tags in the org files."
|
||||||
|
(seq-reduce
|
||||||
|
;; all-tags is in (tags . tags->files) form
|
||||||
|
(lambda (all-tags file)
|
||||||
|
(if (get-file-global-props file "PAGE")
|
||||||
|
;; Ignore pages
|
||||||
|
all-tags
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents file)
|
||||||
|
(let ((tags (mapcar #'car (org-get-buffer-tags))))
|
||||||
|
(seq-reduce
|
||||||
|
(lambda (result tag)
|
||||||
|
(let ((tag-list (car result))
|
||||||
|
(tag->file (cdr result)))
|
||||||
|
(cons
|
||||||
|
;; Tag list
|
||||||
|
(if (member tag tag-list) tag-list (sort (cons tag tag-list) 'string<))
|
||||||
|
;; tag->file
|
||||||
|
(cons (cons tag
|
||||||
|
;; Current value of the the given tag (all the files
|
||||||
|
;; that contain that tag)
|
||||||
|
(append (list file) (cdr (assoc tag tag->file))))
|
||||||
|
tag->file))))
|
||||||
|
tags
|
||||||
|
all-tags)))))
|
||||||
|
(all-org-files)
|
||||||
|
'()))
|
||||||
|
|
||||||
|
|
||||||
(defun get-all-posts ()
|
(defun get-all-posts ()
|
||||||
|
@ -188,7 +220,7 @@ Not pages."
|
||||||
;; We will use the org-agenda to extract all the tags
|
;; We will use the org-agenda to extract all the tags
|
||||||
|
|
||||||
;;; Set the dir containing org the org-files
|
;;; Set the dir containing org the org-files
|
||||||
(setq org-directory (expand-file-name "/site/" build-dir))
|
(setq org-directory (expand-file-name "site" build-dir))
|
||||||
|
|
||||||
;;; Discover all the org files
|
;;; Discover all the org files
|
||||||
(setq org-agenda-files (all-org-files))
|
(setq org-agenda-files (all-org-files))
|
||||||
|
@ -204,17 +236,24 @@ Not pages."
|
||||||
|
|
||||||
|
|
||||||
(let ((base-url (if (prod-p) "https://fg42.org" "http://localhost:3003")))
|
(let ((base-url (if (prod-p) "https://fg42.org" "http://localhost:3003")))
|
||||||
(copy-template (from-root "/docs/sites/templates/index.org")
|
|
||||||
(expand-file-name "/site/index.org" build-dir)
|
|
||||||
(latest-org-list base-url))
|
|
||||||
|
|
||||||
(copy-template (from-root "/docs/sites/templates/categories.org")
|
(copy-template (from-root "/docs/site/templates/index.org")
|
||||||
(expand-file-name "/site/categories/index.org" build-dir)
|
(expand-file-name "site/index.org" build-dir)
|
||||||
(category-org-list))
|
(list
|
||||||
|
(cons :links
|
||||||
|
(latest-org-list base-url))))
|
||||||
|
|
||||||
(copy-template (from-root "/docs/sites/templates/tags.org")
|
(copy-template (from-root "/docs/site/templates/categories.org")
|
||||||
(expand-file-name "/site/tags/index.org" build-dir)
|
(expand-file-name "site/categories/index.org" build-dir)
|
||||||
(tags-org-list))))
|
(list
|
||||||
|
(cons :links
|
||||||
|
(category-org-list))))
|
||||||
|
|
||||||
|
(copy-template (from-root "/docs/site/templates/tags.org")
|
||||||
|
(expand-file-name "site/tags/index.org" build-dir)
|
||||||
|
(list
|
||||||
|
(cons :links
|
||||||
|
(tags-org-list))))))
|
||||||
|
|
||||||
(provide 'fg42/build/docs)
|
(provide 'fg42/build/docs)
|
||||||
;;; docs.el ends here
|
;;; docs.el ends here
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
;;; Buid --- The builder for FG42 -*- lexical-binding: t; -*-
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2010-2021 Sameer Rahmani & Contributors
|
||||||
|
;;
|
||||||
|
;; Author: Sameer Rahmani <lxsameer@gnu.org>
|
||||||
|
;; URL: https://gitlab.com/FG42/FG42
|
||||||
|
;; Version: 3.0.0
|
||||||
|
;;
|
||||||
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
;; the Free Software Foundation, either version 3 of the License, or
|
||||||
|
;; (at your option) any later version.
|
||||||
|
;;
|
||||||
|
;; This program is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
;;
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with thnis program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
;;
|
||||||
|
;;; Commentary:
|
||||||
|
;; Cubes are the building blocks of any `FG42' editor. Each `cube' is a
|
||||||
|
;; unit which defines different abilities in a deterministic and idempotent
|
||||||
|
;; way. Cubes are composable and a composition of cubes creates an editor.
|
||||||
|
;;
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'org-element)
|
||||||
|
|
||||||
|
|
||||||
|
(defmacro comment (&rest _)
|
||||||
|
"Ignore the given BODY."
|
||||||
|
nil)
|
||||||
|
|
||||||
|
|
||||||
|
(defun ->epoch (date-str)
|
||||||
|
"Convert the given DATE-STR to epoch seconds."
|
||||||
|
;; Just because it's easier to deal with date in bash rather than elisp
|
||||||
|
(string-to-number
|
||||||
|
(shell-command-to-string (concat (format "date -d %s" date-str) " +%s"))))
|
||||||
|
|
||||||
|
|
||||||
|
(defun get-buffer-global-props (prop)
|
||||||
|
"Get a plists of global org properties PROP of current buffer."
|
||||||
|
(car
|
||||||
|
(org-element-map
|
||||||
|
(org-element-parse-buffer)
|
||||||
|
'keyword
|
||||||
|
(lambda (el)
|
||||||
|
(when (string-match prop (org-element-property :key el))
|
||||||
|
(org-element-property :value el))))))
|
||||||
|
|
||||||
|
|
||||||
|
(defun get-file-global-props (file prop)
|
||||||
|
"Return the value of the given global PROP in the given org FILE."
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents file)
|
||||||
|
(get-buffer-global-props prop)))
|
||||||
|
|
||||||
|
|
||||||
|
(provide 'fg42/build/utils)
|
||||||
|
;;; utils.el ends here
|
|
@ -4,4 +4,4 @@
|
||||||
#+PAGE: true
|
#+PAGE: true
|
||||||
#+TITLE: Categories
|
#+TITLE: Categories
|
||||||
|
|
||||||
<<<links>>>
|
<<<:links>>>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
#+SETUPFILE: ../config.org
|
#+SETUPFILE: ../config.org
|
||||||
#+OPTIONS: toc:nil
|
#+OPTIONS: toc:nil
|
||||||
#+EXPORT_FILE_NAME: index.html
|
#+EXPORT_FILE_NAME: index.html
|
||||||
|
@ -9,6 +10,6 @@
|
||||||
#+INCLUDE: "../../../README.org::*Future Gadgets 42" :only-contents t
|
#+INCLUDE: "../../../README.org::*Future Gadgets 42" :only-contents t
|
||||||
|
|
||||||
* Recent updates:
|
* Recent updates:
|
||||||
<<<links>>>
|
<<<:links>>>
|
||||||
|
|
||||||
#+INCLUDE: "../../../README.org::*License"
|
#+INCLUDE: "../../../README.org::*License"
|
||||||
|
|
|
@ -5,4 +5,4 @@
|
||||||
#+TITLE: Tags
|
#+TITLE: Tags
|
||||||
|
|
||||||
|
|
||||||
<<<links>>>
|
<<<:links>>>
|
||||||
|
|
Loading…
Reference in New Issue