Skip to content

Commit

Permalink
Rename org-hugo-get-heading-slug to org-hugo--heading-get-slug
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalmodi committed Mar 16, 2022
1 parent 26ca1cb commit 3dcd042
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
25 changes: 12 additions & 13 deletions ox-hugo.el
Expand Up @@ -1869,7 +1869,7 @@ Return nil if id is not found."
(goto-char element-begin)
(org-id-get))))

(defun org-hugo-get-heading-slug(heading info)
(defun org-hugo--heading-get-slug(heading info)
"Return the slug string derived from an Org HEADING element.
1. If HEADING has `:EXPORT_FILE_NAME' and `:EXPORT_HUGO_SLUG'
Expand Down Expand Up @@ -1899,30 +1899,30 @@ INFO is a plist used as a communication channel."
(let ((current-elem-post-subtree-p (org-string-nw-p (org-export-get-node-property :EXPORT_FILE_NAME heading)))
(file (org-string-nw-p (org-export-get-node-property :EXPORT_FILE_NAME heading :inherited)))
hugo-slug bundle slug)
;; (message "[org-hugo-get-heading-slug DBG] EXPORT_FILE_NAME: %S" file)
;; (message "[org-hugo--heading-get-slug DBG] EXPORT_FILE_NAME: %S" file)
(when file
(setq hugo-slug (org-string-nw-p (org-export-get-node-property :EXPORT_HUGO_SLUG heading :inherited))))
(unless hugo-slug
(setq bundle (org-string-nw-p (org-export-get-node-property :EXPORT_HUGO_BUNDLE heading :inherited)))
;; (message "[org-hugo-get-heading-slug DBG] EXPORT_HUGO_BUNDLE: %S" bundle)
;; (message "[org-hugo--heading-get-slug DBG] EXPORT_HUGO_BUNDLE: %S" bundle)
)

(cond
(hugo-slug
;; (message "[org-hugo-get-heading-slug DBG] hugo-slug: %S" hugo-slug)
;; (message "[org-hugo--heading-get-slug DBG] hugo-slug: %S" hugo-slug)
(setq slug hugo-slug))
;; Leaf or branch bundle landing page.
((and bundle file (member file '("index" ;Leaf bundle
"_index" ;Branch bundle
)))
(setq slug bundle)
;; (message "[org-hugo-get-heading-slug DBG] bundle slug: %S" slug)
;; (message "[org-hugo--heading-get-slug DBG] bundle slug: %S" slug)
)
;; It's a Hugo page bundle, but the file is neither index nor
;; _index. So likely a page in a branch bundle.
((and bundle file)
(setq slug (concat (file-name-as-directory bundle) file))
;; (message "[org-hugo-get-heading-slug DBG] branch bundle file slug: %S" slug)
;; (message "[org-hugo--heading-get-slug DBG] branch bundle file slug: %S" slug)
)
;; Only EXPORT_FILE_NAME is set.
(file
Expand All @@ -1949,8 +1949,8 @@ INFO is a plist used as a communication channel."
(setq slug (concat (file-name-as-directory section)
(mapconcat #'file-name-as-directory fragments "")
slug)))
;; (message "[org-hugo-get-heading-slug DBG] section: %S" section)
;; (message "[org-hugo-get-heading-slug DBG] section + slug: %S" slug)
;; (message "[org-hugo--heading-get-slug DBG] section: %S" section)
;; (message "[org-hugo--heading-get-slug DBG] section + slug: %S" slug)
))

;; Finally use the `:title' property to add anchor if applicable.
Expand All @@ -1960,10 +1960,10 @@ INFO is a plist used as a communication channel."
(org-export-data-with-backend
(org-element-property :title heading) 'md info)
:allow-double-hyphens))))
;; (message "[org-hugo-get-heading-slug DBG] anchor: %S" anchor)
;; (message "[org-hugo--heading-get-slug DBG] anchor: %S" anchor)
(when (org-string-nw-p anchor)
(setq slug (format "%s#%s" (or slug "") anchor)))))
;; (message "[org-hugo-get-heading-slug DBG] FINAL slug: %S" slug)
(message "[org-hugo--heading-get-slug DBG] FINAL slug: %S" slug)
slug))

(defun org-hugo-get-md5(element info)
Expand All @@ -1977,7 +1977,6 @@ This function will never return nil."
(org-element-property :title element) 'md info))
"")))
(substring (md5 title) 0 hash-len)))

(defun org-hugo--get-anchor(element info)
"Return anchor string for Org heading ELEMENT.
Expand Down Expand Up @@ -4460,8 +4459,8 @@ links."
(unless (plist-get info :with-broken-links)
(user-error "Unable to resolve link: %S" (nth 1 err))))))
(org-export-resolve-id-link link (org-export--collect-tree-properties ast info))))
(source-path (org-hugo-get-heading-slug link info))
(destination-path (org-hugo-get-heading-slug destination info))
(source-path (org-hugo--heading-get-slug link info))
(destination-path (org-hugo--heading-get-slug destination info))
(destination-type (org-element-type destination)))
;; (message "[ox-hugo pre process DBG] destination type: %s" destination-type)

Expand Down
36 changes: 18 additions & 18 deletions test/ert/tslug.el
Expand Up @@ -32,14 +32,14 @@
(org-test-with-parsed-data
"* <point>"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

(should
(string= "#some-heading"
(org-test-with-parsed-data
"* Some Heading<point>"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

;; Only EXPORT_HUGO_SLUG, and no EXPORT_FILE_NAME. So heading is
;; used for deriving slug.
Expand All @@ -51,7 +51,7 @@
:EXPORT_HUGO_SLUG: slug
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

;; EXPORT_FILE_NAME + EXPORT_HUGO_SLUG
(should
Expand All @@ -63,7 +63,7 @@
:EXPORT_HUGO_SLUG: slug
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

;; EXPORT_FILE_NAME + EXPORT_HUGO_SLUG + EXPORT_HUGO_SECTION
(should
Expand All @@ -79,7 +79,7 @@
:EXPORT_HUGO_SLUG: slug
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info))))))
(org-hugo--heading-get-slug el info))))))

(ert-deftest test-slug/export-file-name ()
"Test derivation of the slug from EXPORT_FILE_NAME."
Expand All @@ -93,7 +93,7 @@
:EXPORT_FILE_NAME: file
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

;; EXPORT_FILE_NAME + EXPORT_HUGO_SECTION
(should
Expand All @@ -108,7 +108,7 @@
:EXPORT_FILE_NAME: file
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info))))))
(org-hugo--heading-get-slug el info))))))

;; Leaf bundles
(ert-deftest test-slug/leaf-bundles ()
Expand All @@ -122,7 +122,7 @@
:EXPORT_FILE_NAME: index
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

;; Leaf bundle in a section
(should
Expand All @@ -138,7 +138,7 @@
:EXPORT_FILE_NAME: index
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info))))))
(org-hugo--heading-get-slug el info))))))

;; Branch bundles
(ert-deftest test-slug/branch-bundles ()
Expand All @@ -151,7 +151,7 @@
:EXPORT_FILE_NAME: _index
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

;; Inherit :EXPORT_HUGO_BUNDLE
(should
Expand All @@ -166,7 +166,7 @@
:EXPORT_FILE_NAME: _index
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

;; Page in branch bundle, inheritance
(should
Expand All @@ -181,7 +181,7 @@
:EXPORT_FILE_NAME: branch-page
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

;; Branch bundle in a section
(should
Expand All @@ -200,7 +200,7 @@
:EXPORT_FILE_NAME: _index
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

;; Branch page in a branch bundle in a section
(should
Expand All @@ -219,7 +219,7 @@
:EXPORT_FILE_NAME: branch-page
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info))))))
(org-hugo--heading-get-slug el info))))))

;; Slugs + anchors
(ert-deftest test-slug/slugs-and-anchors ()
Expand All @@ -238,7 +238,7 @@
:END:
*** Some Heading<point>"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

;; Anchor on a leaf bundle in a section
(should
Expand All @@ -255,7 +255,7 @@
:END:
*** Some Heading<point>"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info))))))
(org-hugo--heading-get-slug el info))))))


;; Section fragments
Expand All @@ -281,7 +281,7 @@
:EXPORT_FILE_NAME: file
:END:"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info)))))
(org-hugo--heading-get-slug el info)))))

;; Anchor on a branch page in a branch bundle in section fragments.
(should
Expand Down Expand Up @@ -310,7 +310,7 @@
:END:
****** Some Heading<point>"
(let ((el (org-element-at-point)))
(org-hugo-get-heading-slug el info))))))
(org-hugo--heading-get-slug el info))))))


(provide 'tslug)

0 comments on commit 3dcd042

Please sign in to comment.