Compare commits

...

3 commits

Author SHA1 Message Date
Óscar Nájera
5e34c09388 refactor contact 2020-06-02 00:11:17 +02:00
Óscar Nájera
edfe13f3af Refactor ox-hugo 2020-06-02 00:11:17 +02:00
Óscar Nájera
0a20ce2b00 Social becomes a section instead of document property
First it changes the entries to categories. That is CV_ENV is now category
for everything. Then cventry continues to behave as before, but CATEGORY
social comes in.

For the moment it creates a formatted block
2020-06-02 00:11:17 +02:00

View file

@ -47,14 +47,29 @@
(:homepage "HOMEPAGE" nil nil parse)
(:address "ADDRESS" nil nil newline)
(:photo "PHOTO" nil nil parse)
(:gitlab "GITLAB" nil nil parse)
(:github "GITHUB" nil nil parse)
(:linkedin "LINKEDIN" nil nil parse)
(:with-email nil "email" t t)
)
:translate-alist '((headline . org-hugocv-headline)
(inner-template . org-hugocv-inner-template)))
(setq org-hugocv--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--crop-edges (x)
"String is <X> so remove first and last chars."
(let ((le (- (length x) 1)))
(substring x 1 le)))
(defun org-hugocv--format-cventry (headline contents info)
"Format HEADLINE as as cventry.
@ -80,6 +95,36 @@ as a communication channel."
contents)))
(defun social-entry (icon url handle)
(let* ((nw-handle (string-trim handle))
(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)))
(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 (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)
@ -87,12 +132,14 @@ contents)))
CONTENTS is the contents of the headline. INFO is a plist used
as a communication channel."
(unless (org-element-property :footnote-section-p headline)
(let ((environment (let ((env (org-element-property :CV_ENV headline)))
(let ((environment (let ((env (org-export-get-category headline info)))
(or (org-string-nw-p env) "block"))))
(cond
;; is a cv entry
((equal environment "cventry")
(org-hugocv--format-cventry headline contents info))
((equal environment "social")
(org-hugocv--format-socialchannels headline contents info))
((org-export-with-backend 'hugo headline contents info))))))
(defun org-hugocv-inner-template (contents info)
@ -104,29 +151,11 @@ holding export options."
(let ((email (and (plist-get info :with-email)
(org-export-data (plist-get info :email) info))))
(when (org-string-nw-p email)
(format "<li class=\"fa fa-envelope\"><a href=\"mailto:%s\"> %s</a></li>\n" email email)))
(social-entry "fa-envelope" "mailto:" email)))
;; homepage
(let ((homepage (org-export-data (plist-get info :homepage) info)))
(when (org-string-nw-p homepage) (format "<li class=\"fa fa-globe\"><a href=\"https://%s\"> %s</a></li>\n" homepage homepage)))
;; social media
(mapconcat (lambda (social-network)
(let ((network (org-export-data
(plist-get info (car social-network))
info)))
(when (org-string-nw-p network)
(format "<li class=\"fa fa-%s\"><a href=\"https://%s/%s\"> %s</a></li>\n"
(nth 1 social-network)
(nth 2 social-network)
network
network))))
'((:github "github" "www.github.com")
(:gitlab "gitlab" "www.gitlab.com")
(:linkedin "linkedin" "www.linkedin.com/in"))
"")
(let ((homepage (org-hugocv--crop-edges (org-export-data (plist-get info :homepage) info))))
(when (org-string-nw-p homepage)
(social-entry "fa-globe" "" homepage)))
"</ul>\n\n"
(org-hugo-inner-template contents info)))