Skip to content

Commit 88b030e

Browse files
authored
Replace by English metadata when relevant (#535)
* Lua filter now works for title and description * working example
1 parent 5992e20 commit 88b030e

File tree

7 files changed

+51
-372
lines changed

7 files changed

+51
-372
lines changed

_quarto-en.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
project:
22
type: website
33
output-dir: "./_site/en"
4+
render:
5+
- index.qmd
6+
# English content
7+
- content/manipulation/01_numpy.qmd
8+
- content/manipulation/02_pandas_intro.qmd
49

5-
lang: en
610

711
website:
812
title: "Python for data science"
@@ -115,3 +119,4 @@ citation:
115119
issued: 2023
116120

117121

122+
lang: en

_quarto-fr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
project:
22
type: website
33

4-
lang: fr
5-
64
website:
75
title: "Python pour la data science"
86
page-footer:
@@ -114,4 +112,6 @@ citation:
114112
url: https://pythonds.linogaliana.fr/
115113
issued: 2023
116114

115+
lang: fr
116+
117117

_quarto.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ project:
55
- index.qmd
66
- content/getting-started/index.qmd
77
- content/manipulation/index.qmd
8-
- content/manipulation/02_pandas_suite.qmd
8+
- content/manipulation/01_numpy.qmd
99
- content/visualisation/index.qmd
1010
- content/modelisation/index.qmd
1111
- content/NLP/index.qmd
@@ -16,6 +16,8 @@ profile:
1616
default: fr
1717
group: [fr, en]
1818

19+
execute:
20+
cache: true
1921

2022
# WEBSITE ARCHITECTURE ---------------------
2123

@@ -68,9 +70,10 @@ format:
6870

6971

7072
# PAGE OPTIONS ---------------------
71-
73+
7274
filters:
73-
- black-formatter
75+
- build/replace-title.lua
76+
#- black-formatter
7477
- build/callout-jupyter.lua
7578

7679
crossref:

build/_printBadges.qmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
```{ojs}
22
//| echo: false
33
path = window.location.pathname.replace(".html", ".qmd");
4-
html`${printBadges({fpath: path})}`
4+
path_modified = (path.includes('en/content')) ? path.replace('en/content', 'content/en') : path
5+
html`${printBadges({fpath: path_modified})}`
56
```
67

8+
79
```{ojs}
810
//| echo: false
911
html`

build/replace-title.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function Meta(meta)
2+
-- Helper function to print metadata table
3+
local function print_meta_table(meta_table)
4+
for key, value in pairs(meta_table) do
5+
print(key, pandoc.utils.stringify(value))
6+
end
7+
end
8+
9+
-- Print entire metadata table
10+
-- print_meta_table(meta)
11+
12+
-- Convert lang to string if it exists
13+
local toto = pandoc.utils.stringify(meta.lang or "")
14+
15+
-- Check if lang contains "en"
16+
if toto and string.find(toto, "en") then
17+
-- Override title with title-en if it exists
18+
if meta['title-en'] then
19+
meta.title = meta['title-en']
20+
quarto.log.output("Title overridden with title-en")
21+
end
22+
if meta['description-en'] then
23+
meta.description = meta['description-en']
24+
quarto.log.output("Description overridden with description-en")
25+
end
26+
27+
end
28+
29+
return meta
30+
end

content/manipulation/01_numpy.qmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ conservons encore `np.random.seed` mais cela peut être amené à évoluer.
103103

104104
::::
105105

106+
:::
107+
108+
::: {.content-visible when-profile="fr"}
109+
106110
:::: {.note}
107111

108112
The authors of `numpy` [now recommend](https://numpy.org/doc/stable/reference/random/index.html) using generators via the `default_rng()` function rather than simply using `numpy.random`.

0 commit comments

Comments
 (0)