Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions build/server-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function generate_section(string $version, ?int $index = null): string {
}

// We added the translation of the documentation in 20
$userManualUrl = "https://docs.skjnldsv.com/server/$label/user_manual/";
$userManualUrl = "server/$label/user_manual/";
if ($version >= 20) {
$userManualUrl .= 'en/';
}
Expand All @@ -32,10 +32,10 @@ function generate_section(string $version, ?int $index = null): string {
$note
<ul class="simple">
<li><a class="reference external" href="$userManualUrl">User Manual</a>
(<a class="reference external" href="https://docs.skjnldsv.com/server/$label/Nextcloud_User_Manual.pdf">Download PDF</a>)</li>
<li><a class="reference external" href="https://docs.skjnldsv.com/server/$label/admin_manual/">Administration Manual</a>
(<a class="reference external" href="https://docs.skjnldsv.com/server/$label/Nextcloud_Server_Administration_Manual.pdf">Download PDF</a>)</li>
<li><a class="reference external" href="https://docs.skjnldsv.com/server/$label/developer_manual/">Developer Manual</a></li>
(<a class="reference external" href="server/$label/Nextcloud_User_Manual.pdf">Download PDF</a>)</li>
<li><a class="reference external" href="server/$label/admin_manual/">Administration Manual</a>
(<a class="reference external" href="server/$label/Nextcloud_Server_Administration_Manual.pdf">Download PDF</a>)</li>
<li><a class="reference external" href="server/$label/developer_manual/">Developer Manual</a></li>
</ul>
</div>
HTML;
Expand Down
79 changes: 72 additions & 7 deletions build/verify-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
* - Template placeholders are replaced
* - Version sections exist
* - Links are properly formatted
* - External links are accessible
* - Relative documentation links point to existing files
*
* Environment Variables:
* - VERIFY_DOCS_BASE_URL: Base URL for documentation files (default: https://docs.nextcloud.com)
* Set to empty string to skip file existence checks
*/

$html_file = 'build/index.html';
$base_url = getenv('VERIFY_DOCS_BASE_URL') ?: 'https://docs.nextcloud.com';

if (!file_exists($html_file)) {
fwrite(STDERR, "⚠️ $html_file not found\n");
Expand Down Expand Up @@ -50,12 +55,15 @@
$version_count = preg_match_all('/<h2>Nextcloud (\d+)/', $content, $versions);
fprintf(STDERR, "✓ Found %d version sections: %s\n", $version_count, implode(', ', $versions[1]));

// Validate documentation links format (should be /server/VERSION/)
$docs_links = array_filter($external_links, fn($l) => preg_match('~docs\.[^/]+/server/~', $l));
// Validate documentation links format (should be server/VERSION/)
// Check both relative links (server/latest, server/stable, etc.) and external docs links
$relative_docs_links = array_filter($relative_links, fn($l) => preg_match('~^server/(latest|stable|\d+)/~', $l));
$external_docs_links = array_filter($external_links, fn($l) => preg_match('~docs\.[^/]+/server/~', $l));
$all_docs_links = array_merge($relative_docs_links, $external_docs_links);

if (!empty($docs_links)) {
$invalid_docs = array_filter($docs_links, fn($l) =>
!preg_match('~/server/(latest|stable|\d+)/~', $l)
if (!empty($all_docs_links)) {
$invalid_docs = array_filter($all_docs_links, fn($l) =>
!preg_match('~(server|/server)/(latest|stable|\d+)/~', $l)
);

if (!empty($invalid_docs)) {
Expand All @@ -64,7 +72,7 @@
fprintf(STDERR, " - %s\n", $link);
}
} else {
fprintf(STDERR, "✓ All %d documentation links are properly formatted\n", count($docs_links));
fprintf(STDERR, "✓ All %d documentation links are properly formatted\n", count($all_docs_links));
}
}

Expand Down Expand Up @@ -106,5 +114,62 @@
exit(1);
}

// Test documentation file existence on deployed site (if base URL is configured)
if ($base_url) {
fprintf(STDERR, "\nVerifying documentation files on %s...\n", $base_url);

$relative_docs = array_filter($relative_links, fn($l) => preg_match('~^server/(latest|stable|\d+)/~', $l));

if (!empty($relative_docs)) {
$missing_files = [];
$timeout_files = [];

foreach ($relative_docs as $relative_path) {
$full_url = rtrim($base_url, '/') . '/' . $relative_path;

$context = stream_context_create([
'http' => [
'method' => 'HEAD',
'timeout' => 5,
'ignore_errors' => true,
'user_agent' => 'Mozilla/5.0'
]
]);

$response = @get_headers($full_url, true, $context);

if ($response === false) {
$timeout_files[] = $relative_path;
fprintf(STDERR, " ⚠️ %s - timeout/offline\n", $relative_path);
} else {
$status_line = $response[0] ?? '';
if (preg_match('/\d{3}/', $status_line, $match)) {
$status = (int)$match[0];
if ($status === 404) {
$missing_files[] = $relative_path;
fprintf(STDERR, " ✗ %s - 404 Not Found\n", $relative_path);
} else if ($status >= 400) {
fprintf(STDERR, " ⚠️ %s - HTTP %d\n", $relative_path, $status);
} else if ($status === 200 || $status === 301 || $status === 302) {
fprintf(STDERR, " ✓ %s\n", $relative_path);
}
}
}
}

if (!empty($missing_files)) {
fprintf(STDERR, "\n❌ ERROR: %d documentation files not found:\n", count($missing_files));
foreach ($missing_files as $file) {
fprintf(STDERR, " - %s\n", $file);
}
exit(1);
}

if (count($timeout_files) >= count($relative_docs) / 2) {
fprintf(STDERR, "\n⚠️ WARNING: %d/%d files timed out (site may be offline)\n", count($timeout_files), count($relative_docs));
}
}
}

fprintf(STDERR, "\n✓ index.html validation passed\n");
exit(0);
Loading