# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

CRATES="
	adler2@2.0.1
	aes@0.8.4
	ahash@0.8.12
	aho-corasick@1.1.4
	android_system_properties@0.1.5
	anstream@1.0.0
	anstyle@1.0.14
	anstyle-parse@1.0.0
	anstyle-query@1.1.5
	anstyle-wincon@3.0.11
	anyhow@1.0.102
	assert-json-diff@2.0.2
	async-compression@0.4.42
	atomic-waker@1.1.2
	autocfg@1.5.1
	base64@0.22.1
	bitflags@2.13.0
	block-buffer@0.10.4
	block2@0.6.2
	bumpalo@3.20.3
	byteorder@1.5.0
	bytes@1.12.0
	cc@1.2.65
	cfg-if@1.0.4
	cfg_aliases@0.2.1
	chrono@0.4.45
	cipher@0.4.4
	clap@4.6.1
	clap_builder@4.6.0
	clap_derive@4.6.1
	clap_lex@1.1.0
	colorchoice@1.0.5
	compression-codecs@0.4.38
	compression-core@0.4.32
	core-foundation-sys@0.8.7
	cpufeatures@0.2.17
	crc32fast@1.5.0
	crypto-common@0.1.7
	cssparser@0.34.0
	cssparser-macros@0.6.1
	ctr@0.9.2
	deadpool@0.12.3
	deadpool-runtime@0.1.4
	derive_more@0.99.20
	digest@0.10.7
	dispatch2@0.3.1
	displaydoc@0.2.6
	dtoa@1.0.11
	dtoa-short@0.3.5
	ego-tree@0.9.0
	equivalent@1.0.2
	find-msvc-tools@0.1.9
	flate2@1.1.9
	fnv@1.0.7
	form_urlencoded@1.2.2
	futf@0.1.5
	futures@0.3.32
	futures-channel@0.3.32
	futures-core@0.3.32
	futures-executor@0.3.32
	futures-io@0.3.32
	futures-macro@0.3.32
	futures-sink@0.3.32
	futures-task@0.3.32
	futures-util@0.3.32
	fxhash@0.2.1
	generic-array@0.14.7
	getopts@0.2.24
	getrandom@0.2.17
	getrandom@0.3.4
	glass_pumpkin@1.9.0
	grammers-client@0.8.1
	grammers-crypto@0.8.0
	grammers-mtproto@0.8.0
	grammers-mtsender@0.8.1
	grammers-session@0.8.0
	grammers-tl-gen@0.8.0
	grammers-tl-parser@1.2.1
	grammers-tl-types@0.8.0
	h2@0.4.15
	hashbrown@0.17.1
	heck@0.5.0
	hermit-abi@0.5.2
	hmac@0.12.1
	html5ever@0.29.1
	http@1.4.2
	http-body@1.0.1
	http-body-util@0.1.3
	httparse@1.10.1
	httpdate@1.0.3
	hyper@1.10.1
	hyper-rustls@0.27.9
	hyper-util@0.1.20
	iana-time-zone@0.1.65
	iana-time-zone-haiku@0.1.2
	icu_collections@2.2.0
	icu_locale_core@2.2.0
	icu_normalizer@2.2.0
	icu_normalizer_data@2.2.0
	icu_properties@2.2.0
	icu_properties_data@2.2.0
	icu_provider@2.2.0
	idna@1.1.0
	idna_adapter@1.2.2
	indexmap@2.14.0
	inout@0.1.4
	ipnet@2.12.0
	is_terminal_polyfill@1.70.2
	itoa@1.0.18
	js-sys@0.3.102
	lazy_static@1.5.0
	libc@0.2.186
	litemap@0.8.2
	locate-locale@0.2.0
	lock_api@0.4.14
	log@0.4.33
	lru-slab@0.1.2
	mac@0.1.1
	markup5ever@0.14.1
	match_token@0.1.0
	matchers@0.2.0
	md-5@0.10.6
	md5@0.8.0
	memchr@2.8.2
	mime@0.3.17
	mime_guess@2.0.5
	miniz_oxide@0.8.9
	mio@1.2.1
	new_debug_unreachable@1.0.6
	nix@0.31.3
	nu-ansi-term@0.50.3
	num-bigint@0.4.6
	num-integer@0.1.46
	num-traits@0.2.19
	num_cpus@1.17.0
	objc2@0.6.4
	objc2-cloud-kit@0.3.2
	objc2-core-data@0.3.2
	objc2-core-foundation@0.3.2
	objc2-core-graphics@0.3.2
	objc2-core-image@0.3.2
	objc2-core-location@0.3.2
	objc2-core-text@0.3.2
	objc2-encode@4.1.0
	objc2-foundation@0.3.2
	objc2-io-surface@0.3.2
	objc2-quartz-core@0.3.2
	objc2-ui-kit@0.3.2
	objc2-user-notifications@0.3.2
	once_cell@1.21.4
	once_cell_polyfill@1.70.2
	os_info@3.15.0
	parking_lot@0.12.5
	parking_lot_core@0.9.12
	pbkdf2@0.12.2
	percent-encoding@2.3.2
	phf@0.11.3
	phf_codegen@0.11.3
	phf_generator@0.11.3
	phf_macros@0.11.3
	phf_shared@0.11.3
	pin-project-lite@0.2.17
	pkg-config@0.3.33
	potential_utf@0.1.5
	ppv-lite86@0.2.21
	precomputed-hash@0.1.1
	proc-macro2@1.0.106
	pure-rust-locales@0.8.2
	quinn@0.11.11
	quinn-proto@0.11.15
	quinn-udp@0.5.14
	quote@1.0.46
	r-efi@5.3.0
	rand@0.8.6
	rand@0.9.4
	rand_chacha@0.9.0
	rand_core@0.6.4
	rand_core@0.9.5
	redox_syscall@0.5.18
	regex@1.12.4
	regex-automata@0.4.14
	regex-syntax@0.8.11
	reqwest@0.12.28
	ring@0.17.14
	rpassword@7.5.4
	rtoolbox@0.0.5
	rustc-hash@2.1.2
	rustls@0.23.41
	rustls-pki-types@1.14.1
	rustls-webpki@0.103.13
	rustversion@1.0.22
	ryu@1.0.23
	scopeguard@1.2.0
	scraper@0.21.0
	selectors@0.26.0
	serde@1.0.228
	serde_core@1.0.228
	serde_derive@1.0.228
	serde_json@1.0.150
	serde_spanned@0.6.9
	serde_urlencoded@0.7.1
	servo_arc@0.4.3
	sha1@0.10.6
	sha2@0.10.9
	sharded-slab@0.1.7
	shlex@2.0.1
	simd-adler32@0.3.9
	siphasher@1.0.3
	slab@0.4.12
	smallvec@1.15.2
	socket2@0.6.4
	sqlite@0.37.0
	sqlite3-src@0.7.0
	sqlite3-sys@0.18.0
	stable_deref_trait@1.2.1
	string_cache@0.8.9
	string_cache_codegen@0.5.4
	strsim@0.11.1
	subtle@2.6.1
	syn@2.0.118
	sync_wrapper@1.0.2
	synstructure@0.13.2
	tendril@0.4.3
	thiserror@2.0.18
	thiserror-impl@2.0.18
	thread_local@1.1.9
	tinystr@0.8.3
	tinyvec@1.11.0
	tinyvec_macros@0.1.1
	tokio@1.52.3
	tokio-macros@2.7.0
	tokio-rustls@0.26.4
	tokio-util@0.7.18
	toml@0.8.23
	toml_datetime@0.6.11
	toml_edit@0.22.27
	toml_write@0.1.2
	tower@0.5.3
	tower-http@0.6.11
	tower-layer@0.3.3
	tower-service@0.3.3
	tracing@0.1.44
	tracing-attributes@0.1.31
	tracing-core@0.1.36
	tracing-log@0.2.0
	tracing-subscriber@0.3.23
	try-lock@0.2.5
	typenum@1.20.1
	unicase@2.9.0
	unicode-ident@1.0.24
	unicode-width@0.2.2
	untrusted@0.9.0
	url@2.5.8
	utf-8@0.7.6
	utf8_iter@1.0.4
	utf8parse@0.2.2
	valuable@0.1.1
	version_check@0.9.5
	want@0.3.1
	wasi@0.11.1+wasi-snapshot-preview1
	wasip2@1.0.4+wasi-0.2.12
	wasm-bindgen@0.2.125
	wasm-bindgen-futures@0.4.75
	wasm-bindgen-macro@0.2.125
	wasm-bindgen-macro-support@0.2.125
	wasm-bindgen-shared@0.2.125
	web-sys@0.3.102
	web-time@1.1.0
	webpki-roots@1.0.8
	winapi@0.3.9
	winapi-i686-pc-windows-gnu@0.4.0
	winapi-x86_64-pc-windows-gnu@0.4.0
	windows-core@0.62.2
	windows-implement@0.60.2
	windows-interface@0.59.3
	windows-link@0.2.1
	windows-result@0.4.1
	windows-strings@0.5.1
	windows-sys@0.52.0
	windows-sys@0.59.0
	windows-sys@0.60.2
	windows-sys@0.61.2
	windows-targets@0.52.6
	windows-targets@0.53.5
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_gnullvm@0.53.1
	windows_aarch64_msvc@0.52.6
	windows_aarch64_msvc@0.53.1
	windows_i686_gnu@0.52.6
	windows_i686_gnu@0.53.1
	windows_i686_gnullvm@0.52.6
	windows_i686_gnullvm@0.53.1
	windows_i686_msvc@0.52.6
	windows_i686_msvc@0.53.1
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnu@0.53.1
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_gnullvm@0.53.1
	windows_x86_64_msvc@0.52.6
	windows_x86_64_msvc@0.53.1
	winnow@0.7.15
	wiremock@0.6.5
	wit-bindgen@0.57.1
	writeable@0.6.3
	yoke@0.8.3
	yoke-derive@0.8.2
	zerocopy@0.8.52
	zerocopy-derive@0.8.52
	zerofrom@0.1.8
	zerofrom-derive@0.1.7
	zeroize@1.9.0
	zerotrie@0.2.4
	zerovec@0.11.6
	zerovec-derive@0.11.3
	zmij@1.0.21
"

RUST_MIN_VER="1.86.0"

inherit cargo systemd

DESCRIPTION="Back up a public Telegram channel into a self-contained Zola static website"
HOMEPAGE="
	https://vitaly-zdanevich.github.io/telegram_channel_to_static_website/
	https://github.com/vitaly-zdanevich/telegram_channel_to_static_website
"
SRC_URI="
	https://github.com/vitaly-zdanevich/telegram_channel_to_static_website/archive/refs/tags/v${PV}.tar.gz
		-> ${P}.tar.gz
	${CARGO_CRATE_URIS}
"
S="${WORKDIR}/telegram_channel_to_static_website-${PV}"

LICENSE="MIT"
# Dependent crate licenses
LICENSE+="
	0BSD Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD BSD-2 Boost-1.0
	CDLA-Permissive-2.0 ISC LGPL-2.1+ MIT MPL-2.0 Unicode-3.0 Unlicense ZLIB
	public-domain
"
SLOT="0"
KEYWORDS="~amd64 ~arm64"
IUSE="mtproto"

DEPEND="dev-db/sqlite:3"
RDEPEND="
	${DEPEND}
	!www-apps/tg2zola-bin
	acct-group/tg2zola
	acct-user/tg2zola
"
BDEPEND="virtual/pkgconfig"

DOCS=( README.md tg2zola.toml )

src_configure() {
	local myfeatures=(
		$(usev mtproto)
	)
	cargo_src_configure
}

src_compile() {
	# Let Portage strip installed binaries instead of Cargo pre-stripping.
	export CARGO_PROFILE_RELEASE_STRIP=false
	cargo_src_compile
}

src_install() {
	dobin "$(cargo_target_dir)/tg2zola"

	exeinto /usr/libexec/tg2zola
	doexe "${FILESDIR}/tg2zola-sync"

	insinto /etc/tg2zola
	doins "${FILESDIR}/tg2zola.conf"
	fowners root:tg2zola /etc/tg2zola/tg2zola.conf
	fperms 0640 /etc/tg2zola/tg2zola.conf

	newinitd "${FILESDIR}/tg2zola.initd" tg2zola
	systemd_dounit "${FILESDIR}/tg2zola.service"
	systemd_dounit "${FILESDIR}/tg2zola.timer"

	keepdir /var/lib/tg2zola
	fowners tg2zola:tg2zola /var/lib/tg2zola
	fperms 0750 /var/lib/tg2zola

	einstalldocs
}

pkg_postinst() {
	if [[ -z ${REPLACING_VERSIONS} ]]; then
		elog "Configure CHANNELS in /etc/tg2zola/tg2zola.conf for automatic daily regeneration."
		elog "OpenRC: rc-update add tg2zola default && rc-service tg2zola start"
		elog "systemd: systemctl enable --now tg2zola.timer"
		elog "Install Zola (e.g. www-apps/zola from ::guru) to build the generated sites."
	fi
}