1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-26 06:44:35 +02:00
This commit is contained in:
Julien Déramond
2022-09-06 21:03:06 +02:00
parent 1bb7e000c7
commit aa05e16b8c
3 changed files with 1901 additions and 1797 deletions

View File

@@ -0,0 +1,89 @@
#!/usr/bin/env node
/*!
* Script to update our glossary semi-automatically based on bootstrap.css.
* Copyright 2017-2022 The Bootstrap Authors
* Copyright 2017-2022 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
'use strict'
const fs = require('fs')
fs.readFile('../dist/css/bootstrap.css', 'utf8', (error, data) => {
if (error) {
throw error
}
// TODO: bootstrap.css should be stripped of its comments to avoid having .map and other elements in the array
// TODO: previous re was /\.[a-zA-Z]([0-9a-zA-Z]*-)*[0-9a-zA-Z]*/gi, optimized
const re = /\.[a-z]([\da-z]*-)*[\da-z]*/gi
const matches = [...data.matchAll(re)]
// Array.from will build an array with just the matching strings
// .sort() will sort those matching strings in the array
// Array.from(new Set(...)) will remove the duplicate entries
const results = Array.from(new Set(Array.from(matches, m => m[0]).sort()))
let newContent = ''
for (const result of results) {
newContent += result + ':\r\n'
}
// Create a temp file containing all classes names as keys and empty values
fs.writeFile('../site/static/docs/5.2/assets/data/glossary.data.temp', newContent, error => {
if (error) {
throw error
}
})
// Compare what's inside our glossary.data and the temp glossary to:
// - remove in glossary.data what doesn't exist anymore
// - add the keys in glossary.data that should be completed with the corresponding links manually
fs.readFile('../site/static/docs/5.2/assets/data/glossary.data', 'utf8', (error, data) => {
if (error) {
throw error
}
const newContentSplit = newContent.split('\r\n')
const finalContentArray = []
// Find all elements that are already in our glossary
// Remove elements that are not in the temp glossary
for (const d of data.split('\r\n')) {
const found = newContentSplit.find(elt => elt.split(':')[0] === d.split(':')[0])
if (found) {
// finalContent += d + '\r\n'
finalContentArray.push(d + '\r\n')
}
}
// Add elements that are new in the temp glossary
for (const d of newContentSplit) {
// Avoid adding empty lines
if (d) {
const found = data.split('\r\n').find(elt => elt.split(':')[0] === d.split(':')[0])
if (!found) {
// finalContent += d + '\r\n'
finalContentArray.push(d + '\r\n')
}
}
}
fs.writeFile('../site/static/docs/5.2/assets/data/glossary.data', finalContentArray.sort().join(''), { flag: 'w' }, error => {
if (error) {
throw error
}
})
fs.unlink('../site/static/docs/5.2/assets/data/glossary.data.temp', error => {
if (error) {
throw error
}
})
})
})

View File

@@ -9,7 +9,22 @@ toc: true
## Glossary
{{< js.inline >}}
{{- ( print "```" "css" "\n" ( readFile (path.Join "site/static/docs" .Site.Params.docs_version "assets/data/glossary.data") ) "\n" "```" ) | markdownify -}}
{{< /js.inline >}}
{{< tables.inline >}}
{{ $file := split (readFile (path.Join "site/static/docs" .Site.Params.docs_version "assets/data/glossary.data")) "\n" }}
<table class="table">
<tbody>
{{- range $file }}
{{ $class := split . ":" }}
<tr>
<td>
{{ if gt (len (string (index $class 1))) 1 }}
<a href="/docs/{{ $.Site.Params.docs_version }}/{{ (index $class 1) }}">{{ index $class 0 }}</a>
{{ else }}
<span>{{ index $class 0 }}</span>
{{ end }}
</td>
</tr>
{{- end -}}
</tbody>
</table>
{{< /tables.inline >}}

File diff suppressed because it is too large Load Diff