# Template file for 'nerd-fonts'
pkgname=nerd-fonts
version=3.1.1
revision=1
build_wrksrc="nerd-fonts-${version}"
depends="nerd-fonts-ttf nerd-fonts-otf"
short_desc="Iconic font aggregator, collection and patcher"
maintainer="cinerea0 <cinerea0@protonmail.com>"
license="MIT"
homepage="https://nerdfonts.com"
changelog="https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/changelog.md"
distfiles="https://github.com/ryanoasis/nerd-fonts/archive/refs/tags/v${version}.tar.gz
 https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/0xProto.tar.xz
 https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/CascadiaMono.tar.xz
 https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/CommitMono.tar.xz
 https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/D2Coding.tar.xz
 https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/GeistMono.tar.xz
 https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/IntelOneMono.tar.xz
 https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/IosevkaTermSlab.tar.xz
 https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/MartianMono.tar.xz
 https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/Monaspace.tar.xz"
checksum="4c4d7f2aceda05ff17789adb2c7046972f4729bc785bc85fd08d0ffde8785e5f
 4c69fe95a7e53feebef29e321d6ed4a4e0c91ad969d8f6ac8ccc66fc6f510528
 e5a0d7ade7f8d85ed55dea69123598646efe7b45955e283c279197b5a9a0c884
 000e052e6112aec08ae6f6a59bf668772f89046758941cca126ec9dfc8915601
 42b66c2c74a4f99f5c069ddd26b3ac6829c85d4f54b857af269cbe1220c48a89
 01d249e0f572346fa5a734db27301a003cd94d75202c382be398c8c63b4a9025
 41f414b484318c3f67bb83b2709c1a148ad5d44348fd761e8a408b25d17ce41f
 57895e55ab3469281f532be362ed3b790f42580005abe3c164c9805d147cc46d
 ee9cf10b84b62025e16904faf90f65f422d628317d410097e544bdfda66479ad
 004b4e08b1c7d1a8a3a1bf990ef29969714521cdb7d7a07c45f229617f2ae876"

post_extract() {
	# move fonts that haven't been renamed
	for font in 0xProto CommitMono D2Coding GeistMono IosevkaTermSlab MartianMono; do
		mv "${font}"* "nerd-fonts-${version}/patched-fonts/${font}/"
	done
	# move fonts that were renamed
	mv CaskaydiaMono* "nerd-fonts-${version}/patched-fonts/CascadiaMono/"
	mv IntoneMono* "nerd-fonts-${version}/patched-fonts/IntelOneMono/"
	mv Monaspice* "nerd-fonts-${version}/patched-fonts/Monaspace/"
}

do_install() {
	vmkdir usr/share/fonts/NerdFonts/otf
	vmkdir usr/share/fonts/NerdFonts/ttf

	# get all patched fonts
	find patched-fonts -name '*.otf' -exec install -Dm644 '{}' "${DESTDIR}/usr/share/fonts/NerdFonts/otf" \;
	find patched-fonts -name '*.ttf' -exec install -Dm644 '{}' "${DESTDIR}/usr/share/fonts/NerdFonts/ttf" \;
	rm "${DESTDIR}"/usr/share/fonts/NerdFonts/ttf/SymbolsNerdFont*.ttf

	vlicense LICENSE
}

nerd-fonts-symbols-ttf_package() {
	short_desc+=" - TTF symbols-only font"
	font_dirs="/usr/share/fonts/NerdFonts/ttf/symbols"
	depends="font-util"
	pkg_install() {
		vmkdir usr/share/fonts/NerdFonts/ttf/symbols
		vcopy "patched-fonts/NerdFontsSymbolsOnly/*.ttf" usr/share/fonts/NerdFonts/ttf/symbols
		vinstall 10-nerd-font-symbols.conf 644 usr/share/fontconfig/conf.avail
	}
}

nerd-fonts-otf_package() {
	short_desc+=" - OTF fonts"
	font_dirs="/usr/share/fonts/NerdFonts/otf"
	depends="font-util"
	pkg_install() {
		vmove usr/share/fonts/NerdFonts/otf
	}
}

nerd-fonts-ttf_package() {
	short_desc+=" - TTF fonts"
	font_dirs="/usr/share/fonts/NerdFonts/ttf"
	depends="font-util nerd-fonts-symbols-ttf"
	pkg_install() {
		vmove usr/share/fonts/NerdFonts/ttf
	}
}
