2018-04-04 23:20:46 +00:00
|
|
|
;;; ox-hugocv.el --- LaTeX hugocv Back-End for Org Export Engine -*- lexical-binding: t; -*-
|
|
|
|
|
2023-10-21 23:21:23 +00:00
|
|
|
;; Package-Requires: ((emacs "28.1") (dash "2.19.1"))
|
2018-04-04 23:20:46 +00:00
|
|
|
;; 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)
|
2023-10-19 17:23:34 +00:00
|
|
|
(require 'dash)
|
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
|
2023-10-21 12:58:55 +00:00
|
|
|
"Options for exporting Org mode files to Hugo-compatible Markdown."
|
2018-04-04 23:20:46 +00:00
|
|
|
:tag "Org Export Hugo CV"
|
|
|
|
:group 'org-export
|
|
|
|
:version "25.3")
|
|
|
|
|
|
|
|
;;; Define Back-End
|
|
|
|
(org-export-define-derived-backend 'hugocv 'hugo
|
|
|
|
:options-alist
|
2023-10-21 12:58:55 +00:00
|
|
|
'((:mobile "MOBILE" nil nil parse)
|
2018-04-04 23:20:46 +00:00
|
|
|
(: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)
|
2023-10-21 23:21:23 +00:00
|
|
|
(:with-email nil "email" t t))
|
2023-10-19 16:28:56 +00:00
|
|
|
:translate-alist '((headline . org-hugocv-headline)))
|
2018-04-04 23:20:46 +00:00
|
|
|
|
2023-10-19 17:23:34 +00:00
|
|
|
(defun org-hugocv--entry-with-icon (field entry)
|
|
|
|
"HTML entry for given FIELD when it is specified in ENTRY."
|
|
|
|
(cl-ecase field
|
2023-10-21 19:59:00 +00:00
|
|
|
(host
|
|
|
|
(-some->> (alist-get 'host entry)
|
2023-10-21 12:58:55 +00:00
|
|
|
(format "%s\n{.cv-host}")))
|
2023-10-19 17:23:34 +00:00
|
|
|
(date
|
|
|
|
(-some->>
|
|
|
|
(org-cv-utils--format-time-window (alist-get 'from-date entry) (alist-get 'to-date entry))
|
2023-10-21 12:58:55 +00:00
|
|
|
(format "%s\n{.cv-date}")))
|
2023-10-19 17:23:34 +00:00
|
|
|
(location
|
|
|
|
(-some->> (alist-get 'location entry)
|
|
|
|
(org-string-nw-p)
|
2023-10-21 12:58:55 +00:00
|
|
|
(format "%s\n{.cv-location}")))))
|
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."
|
2023-10-21 19:59:00 +00:00
|
|
|
(let* ((environment (org-export-get-tags headline info))
|
|
|
|
(env-class (string-replace "cv" "" (cl-find-if (lambda (s) (string-prefix-p "cv" s)) environment)))
|
|
|
|
(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))
|
2023-10-21 19:59:00 +00:00
|
|
|
(title (concat (make-string (+ loffset level) ?#) " "
|
|
|
|
(alist-get 'title entry)
|
|
|
|
" {.cv-role}")))
|
|
|
|
(format "<div class=\"cv-%s\">\n\n%s\n\n%s\n\n%s\n</div>"
|
|
|
|
env-class
|
|
|
|
title
|
2023-10-21 12:58:55 +00:00
|
|
|
(mapconcat (lambda (field) (org-hugocv--entry-with-icon field entry))
|
2023-10-21 19:59:00 +00:00
|
|
|
'(host date location)
|
2023-10-21 12:58:55 +00:00
|
|
|
"\n")
|
|
|
|
contents)))
|
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)
|
2023-10-21 12:58:55 +00:00
|
|
|
(let ((environment (org-export-get-tags headline info)))
|
2018-04-04 23:20:46 +00:00
|
|
|
(cond
|
2023-10-21 19:59:00 +00:00
|
|
|
((cl-find-if (lambda (s) (string-prefix-p "cv" s)) environment)
|
2018-04-04 23:20:46 +00:00
|
|
|
(org-hugocv--format-cventry headline contents info))
|
|
|
|
((org-export-with-backend 'hugo headline contents info))))))
|
|
|
|
|
|
|
|
(provide 'ox-hugocv)
|
2023-10-21 12:58:55 +00:00
|
|
|
;;; ox-hugocv.el ends here
|