2018-04-04 23:20:46 +00:00
|
|
|
;;; ox-hugocv.el --- LaTeX hugocv Back-End for Org Export Engine -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;; Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
;; Author: Oscar Najera <hi AT oscarnajera.com DOT com>
|
|
|
|
;; Keywords: org, wp, tex
|
|
|
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
;; any later version.
|
|
|
|
;;
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; This library implements a LaTeX hugocv back-end, derived from the
|
|
|
|
;; LaTeX one.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
(require 'ox-hugo)
|
2019-02-02 17:50:46 +00:00
|
|
|
(require 'org-cv-utils)
|
2018-04-04 23:20:46 +00:00
|
|
|
|
|
|
|
;;; User-Configurable Variables
|
|
|
|
|
|
|
|
(defgroup org-export-hugocv nil
|
|
|
|
"Options for exporting Org mode files to Hugo-compatible Markdown"
|
|
|
|
:tag "Org Export Hugo CV"
|
|
|
|
:group 'org-export
|
|
|
|
:version "25.3")
|
|
|
|
|
|
|
|
;;; Define Back-End
|
|
|
|
(org-export-define-derived-backend 'hugocv 'hugo
|
|
|
|
:options-alist
|
|
|
|
'(
|
|
|
|
(:mobile "MOBILE" nil nil parse)
|
|
|
|
(:homepage "HOMEPAGE" nil nil parse)
|
|
|
|
(:address "ADDRESS" nil nil newline)
|
|
|
|
(:photo "PHOTO" nil nil parse)
|
|
|
|
(:with-email nil "email" t t)
|
|
|
|
)
|
|
|
|
:translate-alist '((headline . org-hugocv-headline)
|
|
|
|
(inner-template . org-hugocv-inner-template)))
|
|
|
|
|
2020-06-01 19:16:28 +00:00
|
|
|
(setq org-hugocv--recognized-social-networks
|
|
|
|
'((:url "https://www.github.com/"
|
2020-06-01 18:48:49 +00:00
|
|
|
:icon "fa-github")
|
2020-06-01 19:16:28 +00:00
|
|
|
(:url "https://www.gitlab.com/"
|
2020-06-01 18:48:49 +00:00
|
|
|
:icon "fa-gitlab")
|
2020-06-01 19:16:28 +00:00
|
|
|
(:url "https://www.linkedin.com/in/"
|
2020-06-01 18:48:49 +00:00
|
|
|
:icon "fa-linkedin")
|
2020-06-01 19:16:28 +00:00
|
|
|
(:url "https://twitter.com/"
|
2020-06-01 18:48:49 +00:00
|
|
|
:icon "fa-twitter")
|
2020-06-01 19:16:28 +00:00
|
|
|
(:url "https://facebook.com/"
|
2020-06-01 18:48:49 +00:00
|
|
|
:icon "fa-facebook")
|
2020-06-01 19:16:28 +00:00
|
|
|
(:url "https://www.instagram.com/"
|
2020-06-01 18:48:49 +00:00
|
|
|
:icon "fa-instagram")))
|
2018-04-04 23:20:46 +00:00
|
|
|
|
2020-06-01 19:16:28 +00:00
|
|
|
(defun org-hugocv--crop-edges (x)
|
|
|
|
"String is <X> so remove first and last chars."
|
|
|
|
(let ((le (- (length x) 1)))
|
|
|
|
(substring x 1 le)))
|
|
|
|
|
2018-04-04 23:20:46 +00:00
|
|
|
(defun org-hugocv--format-cventry (headline contents info)
|
|
|
|
"Format HEADLINE as as cventry.
|
|
|
|
CONTENTS holds the contents of the headline. INFO is a plist used
|
|
|
|
as a communication channel."
|
2020-06-01 17:54:47 +00:00
|
|
|
(let* ((entry (org-cv-utils--parse-cventry headline info))
|
2018-09-14 09:17:06 +00:00
|
|
|
(loffset (string-to-number (plist-get info :hugo-level-offset))) ;"" -> 0, "0" -> 0, "1" -> 1, ..
|
|
|
|
(level (org-export-get-relative-level headline info))
|
2020-06-01 17:54:47 +00:00
|
|
|
(title (concat (make-string (+ loffset level) ?#) " " (alist-get 'title entry))))
|
2019-02-02 15:04:30 +00:00
|
|
|
(format "\n%s
|
|
|
|
|
|
|
|
<ul class=\"cventry\">
|
|
|
|
<li class=\"fa fa-building\"> %s</li>
|
|
|
|
<li class=\"fa fa-map-marker\"> %s</li>
|
|
|
|
<li class=\"fa fa-calendar\"> %s</li>
|
|
|
|
</ul>
|
2018-04-04 23:20:46 +00:00
|
|
|
|
|
|
|
%s
|
2020-06-01 17:54:47 +00:00
|
|
|
" title
|
|
|
|
(alist-get 'employer entry)
|
|
|
|
(alist-get 'location entry)
|
|
|
|
(org-cv-utils--format-time-window (alist-get 'from-date entry) (alist-get 'to-date entry))
|
|
|
|
contents)))
|
|
|
|
|
2018-04-04 23:20:46 +00:00
|
|
|
|
2020-05-21 11:56:04 +00:00
|
|
|
(defun social-entry (icon url handle)
|
|
|
|
(let* ((nw-handle (string-trim handle))
|
2020-06-01 18:48:49 +00:00
|
|
|
(icon-wrap (if (org-string-nw-p icon)
|
|
|
|
(format "<i class=\"fa %s\"> %s</i>" icon nw-handle) nw-handle)))
|
2020-06-01 19:16:28 +00:00
|
|
|
(format "<a href=\"%s%s\">%s</a>" url nw-handle icon-wrap)))
|
2020-06-01 18:48:49 +00:00
|
|
|
|
|
|
|
(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))
|
2020-05-21 11:56:04 +00:00
|
|
|
|
|
|
|
(defun org-hugocv--format-socialchannels (headline contents info)
|
|
|
|
(let* ((channel (downcase (org-export-data (org-element-property :title headline) info)))
|
2020-06-01 18:48:49 +00:00
|
|
|
(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)))))
|
2018-04-04 23:20:46 +00:00
|
|
|
|
|
|
|
;;;; Headline
|
|
|
|
(defun org-hugocv-headline (headline contents info)
|
|
|
|
"Transcode HEADLINE element into hugocv code.
|
|
|
|
CONTENTS is the contents of the headline. INFO is a plist used
|
|
|
|
as a communication channel."
|
|
|
|
(unless (org-element-property :footnote-section-p headline)
|
2020-05-21 11:56:04 +00:00
|
|
|
(let ((environment (let ((env (org-export-get-category headline info)))
|
2019-02-02 15:48:03 +00:00
|
|
|
(or (org-string-nw-p env) "block"))))
|
2018-04-04 23:20:46 +00:00
|
|
|
(cond
|
|
|
|
;; is a cv entry
|
|
|
|
((equal environment "cventry")
|
|
|
|
(org-hugocv--format-cventry headline contents info))
|
2020-05-21 11:56:04 +00:00
|
|
|
((equal environment "social")
|
|
|
|
(org-hugocv--format-socialchannels headline contents info))
|
2018-04-04 23:20:46 +00:00
|
|
|
((org-export-with-backend 'hugo headline contents info))))))
|
|
|
|
|
|
|
|
(defun org-hugocv-inner-template (contents info)
|
|
|
|
"Return body of document after converting it to Hugo-compatible Markdown.
|
|
|
|
CONTENTS is the transcoded contents string. INFO is a plist
|
|
|
|
holding export options."
|
|
|
|
(concat "<ul id=\"cvcontacts\">\n"
|
|
|
|
;; email
|
|
|
|
(let ((email (and (plist-get info :with-email)
|
|
|
|
(org-export-data (plist-get info :email) info))))
|
2019-02-02 16:47:47 +00:00
|
|
|
(when (org-string-nw-p email)
|
2020-06-01 19:16:28 +00:00
|
|
|
(social-entry "fa-envelope" "mailto:" email)))
|
2018-04-04 23:20:46 +00:00
|
|
|
;; homepage
|
2020-06-01 19:16:28 +00:00
|
|
|
(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)))
|
2018-04-04 23:20:46 +00:00
|
|
|
"</ul>\n\n"
|
|
|
|
(org-hugo-inner-template contents info)))
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'ox-hugocv)
|
|
|
|
;;; ox-hugocv ends here
|