@@ 998,22 998,30 @@ Return the list of results."
(link-text (substring (car (cdr splitted)) 0 -2)) ; Omit the ending ]]
(id (car (cdr (assoc custom-id mapping))))
(type (car (cdr (cdr (assoc custom-id mapping))))))
- ;; I need to know the type to know whether to link to a page or an article.
- (format "[[file:{filename}/%ss/%s/%s.rst][%s]]"
- type
- opel-output-dir-name
- id
- link-text)))
+ (if (null id)
+ ;; This is an internal link /within/ a post.
+ matched-text
+ ;; Link to another post.
+ ;; I need to know the type to know whether to link to a page or an article.
+ (format "[[file:{filename}/%ss/%s/%s.rst][%s]]"
+ type
+ opel-output-dir-name
+ id
+ link-text))))
(defun opel--sub-internal-link-wo-text (matched-text mapping)
"Convert \[\[#blah]] to the appropriate link for Pelican."
(let* ((custom-id (substring (car splitted) 2 -2))
(id (car (cdr (assoc custom-id mapping))))
(type (car (cdr (cdr (assoc custom-id mapping))))))
- (format "[[file:{filename}/%ss/%s/%s.rst]]"
- type
- opel-output-dir-name
- id)))
+ (if (null id)
+ ;; This is an internal link /within/ a post.
+ matched-text
+ ;; Link to another post.
+ (format "[[file:{filename}/%ss/%s/%s.rst]]"
+ type
+ opel-output-dir-name
+ id))))
(defun opel--fix-internal-links (post-text custom-id mapping)
@@ 92,9 92,13 @@ heading as a Pelican post:
Do not nest pelican posts. I have no idea what will happen if you do,
and I do not plan on catching that scenario.
-*** Linking To Another Post
+*** Links
+**** Linking To Another Post
If you want a link to another post, assign the post a ~CUSTOM_ID~
property, and create an [[https://orgmode.org/manual/Internal-Links.html][internal link]].
+**** Linking to a Headline Within a Post
+Just as with links to other posts, assign the node a ~CUSTOM_ID~
+property and create an [[https://orgmode.org/manual/Internal-Links.html][internal link]].
*** Images
To insert an image, enter:
@@ 303,7 307,7 @@ updating it without a backup plan!/
Here are all the function definitions.
-#+name: all-definitions
+#+name: opel-all-definitions
#+BEGIN_SRC elisp :lexical t :tangle opel.el
<<header>>
<<license>>
@@ 1756,6 1760,12 @@ Return the list of results."
#+RESULTS: custom-id-mapping
: opel--construct-customid-mapping
**** Fix Internal Links
+
+We need to distinguish between links to other posts and links to a
+headline within the current post. Both will be linked to using
+~CUSTOM_ID~. The latter, though, will not be in our mapping, and that's
+how we'll distinguish them.
+
#+name: sub-internal-link
#+BEGIN_SRC elisp
(defun opel--sub-internal-link-with-text (matched-text mapping)
@@ 1775,22 1785,30 @@ Return the list of results."
(link-text (substring (car (cdr splitted)) 0 -2)) ; Omit the ending ]]
(id (car (cdr (assoc custom-id mapping))))
(type (car (cdr (cdr (assoc custom-id mapping))))))
- ;; I need to know the type to know whether to link to a page or an article.
- (format "[[file:{filename}/%ss/%s/%s.rst][%s]]"
- type
- opel-output-dir-name
- id
- link-text)))
+ (if (null id)
+ ;; This is an internal link /within/ a post.
+ matched-text
+ ;; Link to another post.
+ ;; I need to know the type to know whether to link to a page or an article.
+ (format "[[file:{filename}/%ss/%s/%s.rst][%s]]"
+ type
+ opel-output-dir-name
+ id
+ link-text))))
(defun opel--sub-internal-link-wo-text (matched-text mapping)
"Convert \[\[#blah]] to the appropriate link for Pelican."
(let* ((custom-id (substring (car splitted) 2 -2))
(id (car (cdr (assoc custom-id mapping))))
(type (car (cdr (cdr (assoc custom-id mapping))))))
- (format "[[file:{filename}/%ss/%s/%s.rst]]"
- type
- opel-output-dir-name
- id)))
+ (if (null id)
+ ;; This is an internal link /within/ a post.
+ matched-text
+ ;; Link to another post.
+ (format "[[file:{filename}/%ss/%s/%s.rst]]"
+ type
+ opel-output-dir-name
+ id))))
#+END_SRC
@@ 2083,3 2101,6 @@ The function that does it all.
(buffer-substring (point-min) (point-max)))))
#+END_SRC
+
+#+RESULTS: opel-convert-heading-to-post
+: opel-convert-heading-to-post