Function: org-publish-collect-index
org-publish-collect-index is a byte-compiled function defined in
ox-publish.el.gz.
Signature
(org-publish-collect-index OUTPUT BACKEND INFO)
Documentation
Update index for a file in cache.
OUTPUT is the output from transcoding current file. BACKEND is the back-end that was used for transcoding. INFO is a plist containing publishing and export options.
The index relative to current file is stored as an alist. An
association has the following shape: (TERM FILE-NAME PARENT),
where TERM is the indexed term, as a string, FILE-NAME is the
original full path of the file where the term in encountered, and
PARENT is a reference to the headline, if any, containing the
original index keyword. When non-nil, this reference is a cons
cell. Its CAR is a symbol among id, custom-id and name and
its CDR is a string.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ox-publish.el.gz
;;; Index generation
(defun org-publish-collect-index (output _backend info)
"Update index for a file in cache.
OUTPUT is the output from transcoding current file. BACKEND is
the back-end that was used for transcoding. INFO is a plist
containing publishing and export options.
The index relative to current file is stored as an alist. An
association has the following shape: (TERM FILE-NAME PARENT),
where TERM is the indexed term, as a string, FILE-NAME is the
original full path of the file where the term in encountered, and
PARENT is a reference to the headline, if any, containing the
original index keyword. When non-nil, this reference is a cons
cell. Its CAR is a symbol among `id', `custom-id' and `name' and
its CDR is a string."
(let ((file (file-truename (plist-get info :input-file))))
(org-publish-cache-set-file-property
file :index
(delete-dups
(org-element-map (plist-get info :parse-tree) 'keyword
(lambda (k)
(when (equal (org-element-property :key k) "INDEX")
(let ((parent (org-export-get-parent-headline k)))
(list (org-element-property :value k)
file
(cond
((not parent) nil)
((let ((id (org-element-property :ID parent)))
(and id (cons 'id id))))
((let ((id (org-element-property :CUSTOM_ID parent)))
(and id (cons 'custom-id id))))
(t (cons 'name
;; Remove statistics cookie.
(replace-regexp-in-string
"\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
(org-element-property :raw-value parent)))))))))
info))))
;; Return output unchanged.
output)