# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
CRATES="
[email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected]
"
RUST_MIN_VER="1.85.0"
inherit cargo
DESCRIPTION="Convert MediaWiki XML dumps into man(7) pages - so you can read Wikipedia in man"
HOMEPAGE="https://gitlab.com/vitaly_zdanevich_wikimedia/wiki2man_on_rust"
SRC_URI="
https://gitlab.com/vitaly_zdanevich_wikimedia/wiki2man_on_rust/-/archive/${PV}/${P}.tar.bz2
${CARGO_CRATE_URIS}
"
LICENSE="
MIT Unicode-3.0 BZIP2
l10n_be? ( CC-BY-SA-4.0 )
l10n_de? ( CC-BY-SA-4.0 )
l10n_en? ( CC-BY-SA-4.0 )
l10n_fr? ( CC-BY-SA-4.0 )
l10n_ja? ( CC-BY-SA-4.0 )
l10n_ru? ( CC-BY-SA-4.0 )
"
SLOT="0"
KEYWORDS="~amd64"
RESTRICT="mirror"
DUMP_DATE="2026-03-01"
DUMP_BASE_URL="https://dumps.wikimedia.org/other/mediawiki_content_current"
WIKIS=(
"be:bewiki"
"en:enwiki"
"ru:ruwiki"
"de:dewiki"
"fr:frwiki"
"ja:jawiki"
)
# Mapping from language code to wiki_id and file chunk
# Format: "l10n_code:wiki_id:chunk"
DUMP_CHUNKS=(
"be:bewiki:p2p803222"
"en:enwiki:p10p1147431"
"en:enwiki:p1147434p3987701"
"en:enwiki:p3987703p8213792"
"en:enwiki:p8213793p13295371"
"en:enwiki:p13295373p18816201"
"en:enwiki:p18816202p24038461"
"en:enwiki:p24038462p29075629"
"en:enwiki:p29075630p34204620"
"en:enwiki:p34204621p39293698"
"en:enwiki:p39293699p43920660"
"en:enwiki:p43920661p48725620"
"en:enwiki:p48725621p53857278"
"en:enwiki:p53857280p58693957"
"en:enwiki:p58693958p63265982"
"en:enwiki:p63265983p67638983"
"en:enwiki:p67638984p71810319"
"en:enwiki:p71810320p76318043"
"en:enwiki:p76318044p80915674"
"en:enwiki:p80915675p82539885"
"ru:ruwiki:p4p2776925"
"ru:ruwiki:p2776926p6496952"
"ru:ruwiki:p6496953p10616532"
"ru:ruwiki:p10616534p11430725"
"de:dewiki:p1p3477200"
"de:dewiki:p3477201p7862771"
"de:dewiki:p7862772p11431923"
"de:dewiki:p11431924p13790678"
"fr:frwiki:p3p3402623"
"fr:frwiki:p3402627p8474856"
"fr:frwiki:p8474857p13488791"
"fr:frwiki:p13488792p17311471"
"ja:jawiki:p1p2410002"
"ja:jawiki:p2410004p5212524"
)
# Split with parameter expansion, not `read <<<`: a here-string needs a temp
# file in ${PWD}, and the depend (metadata) phase can run with an unwritable
# CWD, which trips the sandbox.
for wiki in "${WIKIS[@]}"; do
IUSE+=" l10n_${wiki%%:*}"
done
for dump in "${DUMP_CHUNKS[@]}"; do
l10n_code="${dump%%:*}"
wiki_id="${dump#*:}"; wiki_id="${wiki_id%%:*}"
chunk="${dump##*:}"
SRC_URI+=" l10n_${l10n_code}? ( ${DUMP_BASE_URL}/${wiki_id}/${DUMP_DATE}/xml/bzip2/${wiki_id}-${DUMP_DATE}-${chunk}.xml.bz2 )"
done
QA_FLAGS_IGNORED="usr/bin/${PN}"
src_unpack() {
local my_A=()
local archive
for archive in ${A}; do
[[ ${archive} == *.xml.bz2 ]] && continue
my_A+=( "${archive}" )
done
local A="${my_A[*]}"
cargo_src_unpack
}
src_prepare() {
default
pushd "${ECARGO_VENDOR}/parse-wiki-text-2-0.2.0" >/dev/null || die
eapply "${FILESDIR}/parse-wiki-text-2-0.2.0-utf8-boundaries.patch"
popd >/dev/null || die
}
src_compile() {
cargo_src_compile
local dump l10n_code wiki_id chunk dump_file
for dump in "${DUMP_CHUNKS[@]}"; do
IFS=":" read -r l10n_code wiki_id chunk <<< "${dump}"
if use "l10n_${l10n_code}"; then
dump_file="${wiki_id}-${DUMP_DATE}-${chunk}.xml.bz2"
einfo "Generating man pages for ${l10n_code} using ${dump_file}..."
mkdir -p "${S}/man_pages/${l10n_code}" || die
"${S}/target/release/${PN}" "${DISTDIR}/${dump_file}" -o "${S}/man_pages/${l10n_code}" || die
fi
done
}
src_install() {
dobin "target/release/${PN}"
local wiki l10n_code shard_dir
local -a manpath_dirs=()
for wiki in "${WIKIS[@]}"; do
IFS=":" read -r l10n_code _ <<< "${wiki}"
if use "l10n_${l10n_code}"; then
einfo "Installing ${l10n_code} man pages..."
insinto "/usr/share/man/${l10n_code}"
# Keep the shard/man7 layout: large Wikipedia dumps can generate millions of
# man pages, and putting them all in one directory can hit ext4 limits.
doins -r "${S}/man_pages/${l10n_code}"/*
# man(1) does not recurse into shard directories, so add every shard
# containing man7 pages to MANPATH through env.d.
for shard_dir in "${ED}/usr/share/man/${l10n_code}"/*; do
[[ -d "${shard_dir}/man7" ]] || continue
manpath_dirs+=( "${shard_dir#${ED}}" )
done
fi
done
if [[ ${#manpath_dirs[@]} -gt 0 ]]; then
printf 'MANPATH="%s"\n' "$(IFS=:; echo "${manpath_dirs[*]}")" > "${T}/99wiki2man" || die
doenvd "${T}/99wiki2man"
fi
}
pkg_postinst() {
local wiki l10n_code
for wiki in "${WIKIS[@]}"; do
IFS=":" read -r l10n_code _ <<< "${wiki}"
if use "l10n_${l10n_code}"; then
einfo "Installed ${l10n_code} man pages. Use: man -L ${l10n_code} 7 <article-title>"
fi
done
elog "If man cannot find them in the current terminal, run:"
elog "source /etc/profile"
}