From 2f3b27a955b570930dcc2c7f3d6a35ccc0bc7f12 Mon Sep 17 00:00:00 2001 From: "lukasz.czaplinski" Date: Thu, 14 Nov 2019 18:12:52 +0100 Subject: [PATCH 1/3] refactor: use stasis for generating all files --- .github/workflows/release.yml | 5 ++--- README.md | 4 +--- doc/intro.md | 2 +- project.clj | 4 ++-- src/resume/core.clj | 27 +++++++++------------------ src/resume/gen.clj | 23 +++++++++++++++++++++++ src/resume/pages.clj | 6 ++++++ src/resume/resume_json.clj | 2 +- src/resume/web.clj | 17 ++--------------- 9 files changed, 47 insertions(+), 43 deletions(-) create mode 100644 src/resume/gen.clj create mode 100644 src/resume/pages.clj diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3b37891..3875138 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,8 +16,7 @@ jobs: - name: Build project id: build_resume_json run: | - lein build-resume-json - lein build-resume-html + lein export echo "##[set-output name=version;]$(cat project.clj | head -n 1 | awk '{ print $3 }' | tr -d '\"')" - name: Tag Release @@ -44,7 +43,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./target/resume.json + asset_path: ./target/dist/resume.json asset_name: resume.json asset_content_type: application/json diff --git a/README.md b/README.md index 5905b82..8afa7cc 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,10 @@ A Clojure site for buidling my resume `org/experience.org` serves as data file, to be edited with Emacs org-mode (or any other editor with org-mode support). Lein tasks can be used to convert into: -- [`resume.json`](https://jsonresume.org) - `lein build-resume-json` - generates `target/resume.json`, -- HTML file - `lein build-resume-html` - generates `target/dist/resume.html`, +- [`resume.json`](https://jsonresume.org) - and then HTML via `lein export`, - Latex source for PDF [TODO] - ## License Copyright © 2019 Łukasz Czapliński diff --git a/doc/intro.md b/doc/intro.md index 19c2bbf..4c64e32 100644 --- a/doc/intro.md +++ b/doc/intro.md @@ -8,4 +8,4 @@ My first attempt uses [JSON](jsonresume.org). ## Doing your own -Open `org/experience.org` in your favourite editor, which hopefully supports Org files. Edit, and then run `lein build-resume.json`. This should give you updated `target/resume.json` in current directory. Now you can upload it, or convert to PDF by yourself. +Open `org/experience.org` in your favourite editor, which hopefully supports Org files. Edit, and then run `lein export`. This should generate files to `target/dist` - HTML and JSON version. PDF coming soon! diff --git a/project.clj b/project.clj index 14015a1..1ee3a33 100644 --- a/project.clj +++ b/project.clj @@ -8,8 +8,8 @@ [org.clojure/core.match "0.3.0"] [selmer "1.12.17"] [stasis "2.5.0"]] - :aliases {"build-resume-json" ["run" "-m" "resume.core/export-resume-json"] - "build-resume-html" ["run" "-m" "resume.web/export"]} + :aliases {"export" ["run" "-m" "resume.core/export"] + "test" ["with-profile" "test" "midje"]} :repl-options {:init-ns resume.core} :ring {:handler resume.web/app} :profiles {:dev {:plugins [[lein-ring "0.12.5"]] diff --git a/src/resume/core.clj b/src/resume/core.clj index 4e4f6d5..3a999b0 100644 --- a/src/resume/core.clj +++ b/src/resume/core.clj @@ -1,21 +1,12 @@ (ns resume.core - (:require [resume.org :as org] - [cheshire.core :as json] - [resume.resume-json :as resume-json])) + (:require [clojure.java.io :as io] + [selmer.parser :as selmer] + [stasis.core :as stasis] + [resume.pages :as pages])) -(def experience-source "org/experience.org") -(def resume-json-build "target/resume.json") +(def export-dir "target/dist") -(defn generate-resume - [] - (->> experience-source - slurp - org/parse - resume-json/export)) - -(defn export-resume-json - "Convert org/experience.org into build/resume.json" - [] - (->> (generate-resume) - (#(json/generate-string % {:pretty true})) - (spit resume-json-build))) +(defn export [] + (selmer/set-resource-path! (io/resource "templates")) + (stasis/empty-directory! export-dir) + (stasis/export-pages pages/all export-dir)) diff --git a/src/resume/gen.clj b/src/resume/gen.clj new file mode 100644 index 0000000..cc91f13 --- /dev/null +++ b/src/resume/gen.clj @@ -0,0 +1,23 @@ +(ns resume.gen + (:require [clojure.java.io :as io] + [resume.org :as org] + [resume.resume-json :as resume-json] + [selmer.parser :as selmer])) + +(def experience-source "org/experience.org") + +(defn resume-json + "Prepare resume.json source" + [] + (->> experience-source + slurp + org/parse + resume-json/export)) + +(defn resume-html + "Prepare resume.html source" + [] + (selmer/render-file "resume.html" {:resume (resume-json) + :css (slurp (io/resource "public/style.css")) + :css-paths ["https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/css/bootstrap.min.css" + "https://cdnjs.cloudflare.com/ajax/libs/octicons/2.0.2/octicons.min.css"]})) diff --git a/src/resume/pages.clj b/src/resume/pages.clj new file mode 100644 index 0000000..f1dc360 --- /dev/null +++ b/src/resume/pages.clj @@ -0,0 +1,6 @@ +(ns resume.pages + (:require [cheshire.core :as cheshire] + [resume.gen :as gen])) + +(def all {"/resume.html" (fn [_req] (gen/resume-html)) + "/resume.json" (fn [_req] (-> (gen/resume-json) (cheshire/generate-string {:pretty true})))}) diff --git a/src/resume/resume_json.clj b/src/resume/resume_json.clj index 448f84b..7232602 100644 --- a/src/resume/resume_json.clj +++ b/src/resume/resume_json.clj @@ -81,4 +81,4 @@ :skills (->> sections-by-name (#(get % "Skills")) :children (map export-skills)) :awards [] :work (->> sections-by-name (#(get % "Experience")) :children (map export-experience)) - :meta {:theme :elegant}})) + :meta {:theme :pumpkin}})) diff --git a/src/resume/web.clj b/src/resume/web.clj index 499e122..5d25447 100644 --- a/src/resume/web.clj +++ b/src/resume/web.clj @@ -1,22 +1,9 @@ (ns resume.web (:require [clojure.java.io :as io] - [resume.core :as core] [selmer.parser :as selmer] + [resume.pages :as pages] [stasis.core :as stasis])) -(defn- resume-page [_request] (selmer/render-file "resume.html" {:resume (core/generate-resume) - :css (slurp (io/resource "public/style.css")) - :css-paths ["https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/css/bootstrap.min.css" - "https://cdnjs.cloudflare.com/ajax/libs/octicons/2.0.2/octicons.min.css"]})) - -(defn- get-pages [] {"/resume.html" resume-page}) - (def app (do (selmer/set-resource-path! (io/resource "templates")) - (stasis/serve-pages get-pages))) - -(def export-dir "target/dist") - -(defn export [] - (stasis/empty-directory! export-dir) - (stasis/export-pages (get-pages) export-dir)) + (stasis/serve-pages pages/all))) From ef4b436cb5ab28e8270acbc6a8144f9e638a6765 Mon Sep 17 00:00:00 2001 From: "lukasz.czaplinski" Date: Thu, 14 Nov 2019 18:13:43 +0100 Subject: [PATCH 2/3] ci: update test script --- .github/workflows/clojure.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clojure.yml b/.github/workflows/clojure.yml index fc5c717..2292d88 100644 --- a/.github/workflows/clojure.yml +++ b/.github/workflows/clojure.yml @@ -12,4 +12,4 @@ jobs: - name: Install dependencies run: lein deps - name: Run tests - run: lein with-profile test midje + run: lein test From 534b9139ac10caedeb41c68870fffdb72f68409d Mon Sep 17 00:00:00 2001 From: "lukasz.czaplinski" Date: Thu, 14 Nov 2019 18:15:38 +0100 Subject: [PATCH 3/3] chore: bump version --- CHANGELOG.md | 5 +++++ project.clj | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e95cf3b..a40a7de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). +## [1.1.1] - 14.11.2019 +### Changed +- Internals & CLI entrypoint - now uses `lein export`. + ## [1.1.0] - 14.11.2019 ### Added - Exporting to HTML with custom JSON resume theme. @@ -10,5 +14,6 @@ All notable changes to this project will be documented in this file. This change ### Added - Export to [json resume](jsonresume.org). +[1.1.1]: https://github.com/scoiatael/resume/compare/v1.1.0...v1.1.1 [1.1.0]: https://github.com/scoiatael/resume/compare/v1.0.0...v1.1.0 [1.0.0]: https://github.com/scoiatael/resume/releases/v1.0.0 diff --git a/project.clj b/project.clj index 1ee3a33..4361d1e 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject resume "1.1.0" +(defproject resume "1.1.1" :description "Resume-from-org generator" :url "http://example.com/FIXME" :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"