Skip to content

Commit 9a59191

Browse files
committed
auto-regenerate API docs on production builds
replace periodic-tables with renamed sveriodic-table, add active element panel to WBM element heatmap
1 parent 7c51db5 commit 9a59191

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

site/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"hastscript": "^7.1.0",
2929
"highlight.js": "^11.7.0",
3030
"mdsvex": "^0.10.6",
31-
"periodic-tables": "^0.1.4",
3231
"prettier": "^2.8.1",
3332
"prettier-plugin-svelte": "^2.9.0",
3433
"rehype-autolink-headings": "^6.1.1",
@@ -39,9 +38,10 @@
3938
"svelte-preprocess": "^5.0.0",
4039
"svelte-toc": "^0.5.1",
4140
"svelte2tsx": "^0.6.0",
41+
"sveriodic-table": "^0.1.1",
4242
"tslib": "^2.4.1",
4343
"typescript": "^4.9.4",
44-
"vite": "^4.0.3"
44+
"vite": "^4.0.4"
4545
},
4646
"prettier": {
4747
"semi": false,
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<script lang="ts">
22
import FormEnergyHist from '$root/data/wbm/2022-12-07-hist-e-form-per-atom.svelte'
33
import DataReadme from '$root/data/wbm/readme.md'
4-
// import { PeriodicTable, Toggle } from 'periodic-tables'
5-
import PeriodicTable from 'periodic-tables'
6-
import Toggle from 'periodic-tables/Toggle.svelte'
4+
import type { ChemicalElement } from 'sveriodic-table'
5+
import { PeriodicTable, TableInset, Toggle } from 'sveriodic-table'
6+
import { pretty_num } from 'sveriodic-table/labels'
77
import elem_counts from './2022-12-30-wbm-element-counts.json'
88
9+
let log_color_scale = false
910
const heatmap_values = Object.values(elem_counts)
1011
const color_map = {
1112
200: `blue`,
1213
35_000: `green`,
1314
80_000: `yellow`,
1415
150_000: `red`,
1516
}
16-
17-
let log = true
17+
let active_element: ChemicalElement
1818
</script>
1919

2020
<DataReadme>
@@ -24,8 +24,16 @@
2424
{/if}
2525
</svelte:fragment>
2626
<svelte:fragment slot="wbm-elements-log">
27-
<span>Log color scale? <Toggle bind:checked={log} /></span>
28-
<PeriodicTable {heatmap_values} {color_map} {log} />
27+
<span>Log color scale <Toggle bind:checked={log_color_scale} /></span>
28+
<PeriodicTable {heatmap_values} {color_map} log={log_color_scale} bind:active_element>
29+
<TableInset slot="inset" grid_row="3">
30+
{#if active_element?.name}
31+
<strong>
32+
{active_element?.name}: {pretty_num(elem_counts[active_element?.symbol])}
33+
</strong>
34+
{/if}
35+
</TableInset>
36+
</PeriodicTable>
2937
</svelte:fragment>
3038
</DataReadme>
3139

@@ -38,4 +46,7 @@
3846
transform: translateX(-50%);
3947
z-index: 1;
4048
}
49+
strong {
50+
text-align: center;
51+
}
4152
</style>

site/vite.config.ts

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import yaml from '@rollup/plugin-yaml'
22
import { sveltekit } from '@sveltejs/kit/vite'
3+
import { exec } from 'child_process'
34
import { resolve } from 'path'
45
import type { UserConfig } from 'vite'
56

@@ -25,3 +26,21 @@ const vite_config: UserConfig = {
2526
}
2627

2728
export default vite_config
29+
30+
if (process.env.PROD) {
31+
// update generated API docs on production builds
32+
const src_url = `https://github.com/janosh/matbench-discovery/blob/main`
33+
const route = `src/routes/api`
34+
await exec(`rm -f ${route}/*.md`)
35+
await exec(
36+
`cd .. && lazydocs matbench_discovery --output-path site/${route} --no-watermark --src-base-url ${src_url}`
37+
)
38+
39+
// remove <b> tags from generated markdown
40+
await exec(`sed -i 's/<b>//g' ${route}/*.md`)
41+
await exec(`sed -i 's/<\\/b>//g' ${route}/*.md`)
42+
// tweak look of badges linking to source code
43+
const old_src = `src="https://img.shields.io/badge/-source-cccccc?style=flat-square"`
44+
const new_src = `src="https://img.shields.io/badge/source-blue?style=flat" alt="source link"`
45+
await exec(`sed -i 's/${old_src}/${new_src}/g' ${route}/*.md`)
46+
}

0 commit comments

Comments
 (0)