From edfe13f3af86b797ca4ab2351ae598b769d2d2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20N=C3=A1jera?= Date: Mon, 1 Jun 2020 20:48:49 +0200 Subject: [PATCH] Refactor ox-hugo --- ox-hugocv.el | 67 +++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/ox-hugocv.el b/ox-hugocv.el index 4a8057c..7f2ed52 100644 --- a/ox-hugocv.el +++ b/ox-hugocv.el @@ -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 " " icon) "%s") "%s")) - (link-wrap (format "%s" url nw-handle icon-wrap)) + (icon-wrap (if (org-string-nw-p icon) + (format " %s" icon nw-handle) nw-handle))) + (format "%s" 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)