Refactor ox-hugo

This commit is contained in:
Óscar Nájera 2020-06-01 20:48:49 +02:00
parent 0a20ce2b00
commit edfe13f3af

View file

@ -52,6 +52,19 @@
:translate-alist '((headline . org-hugocv-headline)
(inner-template . org-hugocv-inner-template)))
(defvar recognized-social-networks
'((:url "https://www.github.com"
:icon "fa-github")
(:url "https://www.gitlab.com"
:icon "fa-gitlab")
(:url "https://www.linkedin.com/in"
:icon "fa-linkedin")
(:url "https://twitter.com"
:icon "fa-twitter")
(:url "https://facebook.com"
:icon "fa-facebook")
(:url "https://www.instagram.com"
:icon "fa-instagram")))
(defun org-hugocv--format-cventry (headline contents info)
"Format HEADLINE as as cventry.
@ -79,40 +92,34 @@ contents)))
(defun social-entry (icon url handle)
(let* ((nw-handle (string-trim handle))
(icon-wrap (if (org-string-nw-p icon) (concat (format "<i class=\"fa %s\"> " icon) "%s</i>") "%s"))
(link-wrap (format "<a href=\"%s/%s\">%s</a>" url nw-handle icon-wrap))
(icon-wrap (if (org-string-nw-p icon)
(format "<i class=\"fa %s\"> %s</i>" icon nw-handle) nw-handle)))
(format "<a href=\"%s/%s\">%s</a>" url nw-handle icon-wrap)))
)
(format link-wrap nw-handle)))
(defun org-hugocv--unknown-social-channels (headline contents info)
(let ((icon (org-export-data (org-element-property :ICON headline) info))
(url (org-export-data (org-element-property :URL headline) info))
(handle (org-export-data contents info)))
(concat
(if (org-string-nw-p icon) ""
(concat (org-export-data (org-element-property :title headline) info) " : "))
(social-entry icon url handle))))
(defun org-hugocv--pick-social-network (channel contents)
(-any (lambda (network)
(when (string-match-p channel (plist-get network :url))
(social-entry (plist-get network :icon)
(plist-get network :url)
contents)))
recognized-social-networks))
(defun org-hugocv--format-socialchannels (headline contents info)
(let* ((channel (downcase (org-export-data (org-element-property :title headline) info)))
(entry (-any (lambda (network) (when (string-match-p channel (plist-get network :url))
(social-entry (plist-get network :icon) (plist-get network :url) contents)))
'((:url "https://www.github.com" :icon "fa-github")
(:url "https://www.gitlab.com" :icon "fa-gitlab")
(:url "https://www.linkedin.com/in" :icon "fa-linkedin")
(:url "https://www.linkedin.com/in" :icon "fa-linkedin")
(:url "https://twitter.com" :icon "fa-twitter")
(:url "https://facebook.com" :icon "fa-facebook")
(:url "https://www.instagram.com" :icon "fa-instagram"))
)))
(cond
(entry entry)
((org-element-property :URL headline)
(let ((icon (org-export-data (org-element-property :ICON headline) info))
(url (org-export-data (org-element-property :URL headline) info))
(handle (org-export-data contents info))
)
(concat (if (org-string-nw-p icon)
""
(concat (org-export-data (org-element-property :title headline) info) " : "))
(social-entry icon url handle))))
((org-export-with-backend 'hugo headline contents info)))
))
(entry (org-hugocv--pick-social-network channel contents)))
(cond (entry entry)
((org-element-property :URL headline)
(org-hugocv--unknown-social-channels headline contents info))
((org-export-with-backend 'hugo headline contents info)))))
;;;; Headline
(defun org-hugocv-headline (headline contents info)