|
| 1 | +--- |
| 2 | +author: |
| 3 | + name: Daniel Slutsky |
| 4 | + image: https://avatars.githubusercontent.com/u/5673102?v=4 |
| 5 | + url: https://scicloj.github.io/contributors/daslu/ |
| 6 | + affiliation: |
| 7 | + - {name: Scicloj, url: 'https://scicloj.github.io/'} |
| 8 | + links: |
| 9 | + - {icon: github, href: 'https://github.com/daslu'} |
| 10 | +description: A demonstration of our practice with some Civitas notebooks that cannot be run in GitHub Pages. |
| 11 | +image: skip-if-unchanged.jpg |
| 12 | +type: post |
| 13 | +date: '2025-07-25' |
| 14 | +category: clay |
| 15 | +tags: [clay, workflow] |
| 16 | +format: |
| 17 | + html: {title: Some Civitas notebooks should only be run locally} |
| 18 | + |
| 19 | +--- |
| 20 | +<style></style><style>.printedClojure .sourceCode { |
| 21 | + background-color: transparent; |
| 22 | + border-style: none; |
| 23 | +} |
| 24 | +</style><style>.clay-limit-image-width .clay-image {max-width: 100%} |
| 25 | +.clay-side-by-side .sourceCode {margin: 0} |
| 26 | +.clay-side-by-side {margin: 1em 0} |
| 27 | +</style> |
| 28 | +<script src="skip_if_unchanged_example_files/md-default0.js" type="text/javascript"></script><script src="skip_if_unchanged_example_files/md-default1.js" type="text/javascript"></script> |
| 29 | +Usually, when we wish to create Clojure Civitas posts, we enjoy the fact |
| 30 | +that Civitas runs our notebooks in the GitHub Actions as it renders the website. |
| 31 | + |
| 32 | +While this is the default behavior, sometimes, we cannot expect our notebooks |
| 33 | +to be run in GitHub Actions. For example, they may depend on a local file |
| 34 | +or service. |
| 35 | + |
| 36 | +This notebook, for example, assumes that you have a local secrets file |
| 37 | +and it will not work without it! |
| 38 | + |
| 39 | + |
| 40 | +::: {.sourceClojure} |
| 41 | +```clojure |
| 42 | +(slurp "/home/daslu/my-secret.txt") |
| 43 | +``` |
| 44 | +::: |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +::: {.printedClojure} |
| 49 | +```clojure |
| 50 | +"this is my secret!!!!!\n" |
| 51 | + |
| 52 | +``` |
| 53 | +::: |
| 54 | + |
| 55 | + |
| 56 | +If you are the author of such a notebook, the recommended practice is to |
| 57 | +render the notebook locally usinc Clay in Quarto `.qmd` format, and include |
| 58 | +that file in your Pull Request. |
| 59 | + |
| 60 | +The `.qmd` file is all that Civitas needs to include your notebook in the |
| 61 | +website. As long as the `.qmd` file is included in the PR, and is not older than |
| 62 | +your source `.clj` file, Civitas will just rely on it and not even try |
| 63 | +to generate it in GitHub Actions. |
| 64 | + |
| 65 | +To do that, you will need to make the file locally with a Quarto target. |
| 66 | + |
| 67 | +Here are two ways to do that: |
| 68 | + |
| 69 | +1. Use the command line. |
| 70 | +Note that here, we use the path to the notebook, relative to `src`. |
| 71 | +```sh |
| 72 | +clojure -M:clay -A:markdown scicloj/clay/skip_if_unchanged_example.clj |
| 73 | +``` |
| 74 | + |
| 75 | +2. .. Or do the same in Clojure code. |
| 76 | + |
| 77 | + |
| 78 | +::: {.sourceClojure} |
| 79 | +```clojure |
| 80 | +(comment |
| 81 | + (require '[scicloj.clay.v2.api :as clay]) |
| 82 | + (clay/make! {:source-path "scicloj/clay/skip_if_unchanged_example.clj" |
| 83 | + :aliases [:markdown]})) |
| 84 | +``` |
| 85 | +::: |
| 86 | + |
| 87 | + |
| 88 | +Now, need to `git add` the generated `qmd` file. |
| 89 | +Here is how. |
| 90 | + |
| 91 | + |
| 92 | +```{=html} |
| 93 | +<div style="background-color:grey;height:2px;width:100%;"></div> |
| 94 | +``` |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | +```{=html} |
| 99 | +<div><pre><small><small>source: <a href="https://github.com/ClojureCivitas/clojurecivitas.github.io/blob/main/src/scicloj/clay/skip_if_unchanged_example.clj">src/scicloj/clay/skip_if_unchanged_example.clj</a></small></small></pre></div> |
| 100 | +``` |
0 commit comments