Skip to content

Commit

Permalink
feat: Add script to get fonts on build
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Dec 8, 2023
1 parent 1a3411f commit c1ee441
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/assets/fonts
tests/clover.xml
.idea
node_modules/
Expand Down
1 change: 1 addition & 0 deletions .nextcloudignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
src
build
.git
tests
node_modules
Expand Down
1 change: 1 addition & 0 deletions assets/fonts/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fonts will be added here during release build thorugh the build/download-fonts.sh script.
Binary file removed assets/fonts/AmaticSC-Regular.ttf
Binary file not shown.
47 changes: 47 additions & 0 deletions build/download-fonts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
#
# Download font files and put them into the assets/fonts folder for the release

FONTLIST=(
"https://github.com/google/fonts/raw/main/ofl/amaticsc/AmaticSC-Regular.ttf"
"https://github.com/google/fonts/raw/main/ofl/amaticsc/AmaticSC-Bold.ttf"
"https://github.com/google/fonts/blob/main/ofl/caveat/Caveat%5Bwght%5D.ttf"
"https://github.com/google/fonts/raw/main/ofl/comfortaa/Comfortaa%5Bwght%5D.ttf"
"https://github.com/google/fonts/raw/main/ofl/ebgaramond/EBGaramond%5Bwght%5D.ttf"
"https://github.com/google/fonts/raw/main/ofl/lexend/Lexend%5Bwght%5D.ttf"
"https://github.com/google/fonts/raw/main/ofl/lobster/Lobster-Regular.ttf"
"https://github.com/google/fonts/raw/main/ofl/lora/Lora%5Bwght%5D.ttf"
"https://github.com/google/fonts/raw/main/ofl/montserrat/Montserrat%5Bwght%5D.ttf"
"https://github.com/google/fonts/raw/main/ofl/nunito/Nunito%5Bwght%5D.ttf"
"https://github.com/google/fonts/raw/main/ofl/oswald/Oswald%5Bwght%5D.ttf"
"https://github.com/google/fonts/raw/main/ofl/pacifico/Pacifico-Regular.ttf"
"https://github.com/google/fonts/raw/main/ofl/playfairdisplay/PlayfairDisplay%5Bwght%5D.ttf"
"https://github.com/google/fonts/blob/main/ofl/roboto/Roboto%5Bwdth%2Cwght%5D.ttf"
"https://github.com/google/fonts/raw/main/apache/robotomono/RobotoMono%5Bwght%5D.ttf"
"https://github.com/google/fonts/blob/main/ofl/spectral/Spectral-Regular.ttf"
)

rm assets/fonts/*

function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }

for font in "${FONTLIST[@]}"; do
echo "$font"
wget -q -P assets/fonts/ $font

FILENAME=$(urldecode "$(basename "$font")")

if [[ $FILENAME == *"wght"* ]]; then
NEWFILENAME=$(echo $FILENAME | sed 's/\[wght\]/-wght/g')
NEWFILENAME=$(echo $NEWFILENAME | sed 's/\[wdth,wght\]/-wdtg-wght/g')
mv assets/fonts/$FILENAME assets/fonts/$NEWFILENAME
else
NEWFILENAME=$(echo $FILENAME)
fi

echo "$FILENAME"
FONTNAME=$(echo $NEWFILENAME | sed 's/.ttf//g')

echo "$(dirname $font)/OFL.txt"
wget -q -O "assets/fonts/$FONTNAME.LICENSE.txt" "$(dirname $font)/OFL.txt"
done
1 change: 1 addition & 0 deletions krankerl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
before_cmds = [
"composer install --working-dir=composer/",
"composer dump --working-dir=composer/",
"bash ./build/download-fonts.sh",
"npm ci",
"npm run build"
]
2 changes: 1 addition & 1 deletion lib/Migration/InstallDefaultFonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getName(): string {
public function run(IOutput $output): void {
$appVersion = $this->config->getAppValue('richdocuments', 'installed_version');

if (!empty($appVersion) && version_compare($appVersion, '8.2.2') < 1) {
if (empty($appVersion) || version_compare($appVersion, '8.3.0', '>')) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/FontService.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function installDefaultFonts(): void {
}

while (false !== ($fileName = readdir($handle))) {
if ($fileName === '.' || $fileName === '..') {
if (\str_starts_with($fileName, '.') || \str_ends_with($fileName, '.txt')) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export default {
fontXmlHint() {
return `
<remote_font_config>
<url desc="URL of optional JSON file that lists fonts to be included in Online" type="string" default="">${this.fontHintUrl}</url>
<url>${this.fontHintUrl}</url>
</remote_font_config>
`
},
Expand Down

0 comments on commit c1ee441

Please sign in to comment.