diff --git a/.github/workflows/appimage-build.yml b/.github/workflows/appimage-build.yml index aebf52d1..2496533f 100644 --- a/.github/workflows/appimage-build.yml +++ b/.github/workflows/appimage-build.yml @@ -62,6 +62,11 @@ jobs: rm -rf AppDir DESTDIR="${PWD}/AppDir" ninja -C build install + - name: Verify offline docs install + run: | + set -eux + test -f AppDir/usr/share/doc/zoitechat/html/index.html + - name: Bundle scripting runtimes in AppDir run: | set -eux diff --git a/.github/workflows/flatpak-build.yml b/.github/workflows/flatpak-build.yml index 2dd4d2c9..0ee5ddb7 100644 --- a/.github/workflows/flatpak-build.yml +++ b/.github/workflows/flatpak-build.yml @@ -37,6 +37,12 @@ jobs: cache: false restore-cache: false + - name: Verify offline docs install + run: | + flatpak --user install -y zoitechat.flatpak + app_dir="$(flatpak info --user --show-location net.zoite.Zoitechat)" + test -f "$app_dir/files/share/doc/net.zoite.Zoitechat/html/index.html" + - name: Upload Flatpak Bundle id: upload_flatpak uses: actions/upload-artifact@v6 diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 18c80755..5527ea2b 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -132,6 +132,16 @@ jobs: msbuild win32\zoitechat.sln /m /verbosity:minimal /p:Configuration=Release /p:Platform=${{ matrix.platform }} shell: cmd + - name: Verify offline docs install + run: | + if not exist "..\zoitechat-build\${{ matrix.platform }}\rel\offline-docs\index.html" exit /b 1 + findstr /C:"Name:" "..\zoitechat-build\${{ matrix.platform }}\bin\zoitechat.iss" | findstr /C:"docs" + findstr /C:"OFFLINEDOCSURL" "..\zoitechat-build\${{ matrix.platform }}\bin\zoitechat.iss" + findstr /C:"Source:" "..\zoitechat-build\${{ matrix.platform }}\bin\zoitechat.iss" | findstr /C:"offline-docs" + findstr /C:"offline-docs.tar.gz" "..\zoitechat-build\${{ matrix.platform }}\bin\zoitechat.iss" + findstr /C:"InstallOfflineDocs" "..\zoitechat-build\${{ matrix.platform }}\bin\zoitechat.iss" + shell: cmd + - name: Preparing Artifacts run: | move ..\zoitechat-build\${{ matrix.platform }}\ZoiteChat-*.exe .\ diff --git a/data/meson.build b/data/meson.build index 975205fa..e6510144 100644 --- a/data/meson.build +++ b/data/meson.build @@ -7,3 +7,15 @@ if get_option('gtk-frontend') subdir('misc') subdir('man') endif + +offline_docs_url = get_option('offline-docs-url') +offline_docs = custom_target('offline-docs', + output: 'offline-docs.stamp', + command: [find_program('python3'), files('misc/fetch_offline_docs.py'), offline_docs_url, '@OUTDIR@', meson.source_root()], + build_by_default: true, +) +meson.add_install_script( + files('misc/install_offline_docs.py'), + join_paths(meson.current_build_dir(), 'offline-docs'), + offline_docs_dir, +) diff --git a/data/misc/fetch_offline_docs.py b/data/misc/fetch_offline_docs.py new file mode 100644 index 00000000..e18261e3 --- /dev/null +++ b/data/misc/fetch_offline_docs.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +import html +import io +import pathlib +import shutil +import sys +import tarfile +import urllib.error +import urllib.request + +url = sys.argv[1] +out_dir = pathlib.Path(sys.argv[2]) +source_dir = pathlib.Path(sys.argv[3]) if len(sys.argv) > 3 else pathlib.Path.cwd() +docs_dir = out_dir / 'offline-docs' +if docs_dir.exists(): + shutil.rmtree(docs_dir) +docs_dir.mkdir(parents=True, exist_ok=True) + +def write_source_docs(): + parts = ['
{html.escape(path.read_text(encoding="utf-8", errors="replace"))}')
+ parts.append('')
+ (docs_dir / 'index.html').write_text('\n'.join(parts), encoding='utf-8')
+
+if url:
+ try:
+ with urllib.request.urlopen(url, timeout=30) as r:
+ data = r.read()
+ with tarfile.open(fileobj=io.BytesIO(data), mode='r:gz') as tar:
+ try:
+ tar.extractall(docs_dir, filter='data')
+ except TypeError:
+ tar.extractall(docs_dir)
+ except (OSError, tarfile.TarError, urllib.error.URLError) as error:
+ print(f'offline docs download failed: {error}', file=sys.stderr)
+ write_source_docs()
+else:
+ write_source_docs()
+(out_dir / 'offline-docs.stamp').write_text('ok')
diff --git a/data/misc/install_offline_docs.py b/data/misc/install_offline_docs.py
new file mode 100644
index 00000000..c1b2beec
--- /dev/null
+++ b/data/misc/install_offline_docs.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python3
+import os
+import pathlib
+import shutil
+import sys
+
+src = pathlib.Path(sys.argv[1])
+dest = pathlib.Path(os.environ['MESON_INSTALL_DESTDIR_PREFIX']) / sys.argv[2]
+if not (src / 'index.html').exists():
+ sys.exit(0)
+if dest.exists():
+ shutil.rmtree(dest)
+shutil.copytree(src, dest)
diff --git a/flatpak/net.zoite.Zoitechat.json b/flatpak/net.zoite.Zoitechat.json
index 8adb58e7..9b37e0ad 100644
--- a/flatpak/net.zoite.Zoitechat.json
+++ b/flatpak/net.zoite.Zoitechat.json
@@ -56,7 +56,8 @@
"-Ddbus-service-use-appid=true",
"-Dwith-perl=perl",
"-Dwith-python=python3",
- "-Dwith-lua=lua"
+ "-Dwith-lua=lua",
+ "-Doffline-docs-package=net.zoite.Zoitechat"
],
"build-options": {
"cflags": "-Wno-error=missing-include-dirs"
diff --git a/meson.build b/meson.build
index ffcfd62f..aa518791 100644
--- a/meson.build
+++ b/meson.build
@@ -32,8 +32,18 @@ config_h = configuration_data()
config_h.set_quoted('PACKAGE_VERSION', meson.project_version())
config_h.set_quoted('PACKAGE_NAME', meson.project_name())
config_h.set_quoted('GETTEXT_PACKAGE', 'zoitechat')
+offline_docs_package = get_option('offline-docs-package')
+if offline_docs_package == ''
+ offline_docs_package = meson.project_name()
+endif
+offline_docs_dir = get_option('offline-docs-dir')
+if offline_docs_dir == ''
+ offline_docs_dir = join_paths(get_option('datadir'), 'doc', offline_docs_package, 'html')
+endif
config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'),
get_option('datadir'), 'locale'))
+config_h.set_quoted('ZOITECHATDOCDIR', join_paths(get_option('prefix'),
+ offline_docs_dir))
config_h.set10('ENABLE_NLS', true)
# Optional features
diff --git a/meson_options.txt b/meson_options.txt
index 04b0265e..63bc81b1 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -62,3 +62,13 @@ option('with-upd', type: 'boolean',
option('with-perl-legacy-api', type: 'boolean', value: false,
description: 'Enables the legacy IRC perl module for compatibility with old scripts'
)
+
+option('offline-docs-url', type: 'string', value: '',
+ description: 'URL for offline documentation archive (tar.gz)'
+)
+option('offline-docs-package', type: 'string', value: '',
+ description: 'Package or app id to use under the installed documentation directory'
+)
+option('offline-docs-dir', type: 'string', value: 'https://dl.zoitechat.org/offlinedocs/zoitechat-docs-html-2.18.1.tar.gz',
+ description: 'Installed offline documentation directory relative to prefix'
+)
diff --git a/packaging/manjaro/PKGBUILD b/packaging/manjaro/PKGBUILD
index 5544d8b3..014a9960 100644
--- a/packaging/manjaro/PKGBUILD
+++ b/packaging/manjaro/PKGBUILD
@@ -66,4 +66,5 @@ build() {
package() {
meson install -C build --destdir "$pkgdir"
+ test -f "$pkgdir/usr/share/doc/zoitechat/html/index.html"
}
diff --git a/src/fe-gtk/fe-gtk.vcxproj b/src/fe-gtk/fe-gtk.vcxproj
index a53f9314..1b8450f5 100644
--- a/src/fe-gtk/fe-gtk.vcxproj
+++ b/src/fe-gtk/fe-gtk.vcxproj
@@ -44,6 +44,7 @@ REM zoitechat.rc needs to be in UCS-2 or Resource Compiler will complain
powershell "Get-Content -Encoding UTF8 '$(ZoiteChatLib)zoitechat.rc.utf8' | Out-File '$(ZoiteChatLib)zoitechat.rc'; Remove-Item '$(ZoiteChatLib)zoitechat.rc.utf8'"
"$(DepsRoot)\bin\glib-compile-resources.exe" --generate-header --manual-register --sourcedir "$(DataDir)" --target "$(ZoiteChatLib)resources.h" "$(DataDir)zoitechat.gresource.xml"
"$(DepsRoot)\bin\glib-compile-resources.exe" --generate-source --manual-register --sourcedir "$(DataDir)" --target "$(ZoiteChatLib)resources.c" "$(DataDir)zoitechat.gresource.xml"
+"$(Python3Path)\python.exe" "$(DataDir)misc\fetch_offline_docs.py" "$(OfflineDocsUrl)" "$(ZoiteChatRel)." "$(SolutionDir).."
]]>