Skip to content
Open
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
2 changes: 2 additions & 0 deletions apps/api/src/services/normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ export class Normalizer {
!enrichment.boardConfigSlugs?.size || enrichment.boardConfigSlugs.has(slug)
? buildCommand(slug)
: null,
instructions_url:
boardImages.find((img) => img.board_instructions)?.board_instructions || null,
legacy_paths: this.getLegacyPaths(slug, enrichment.redirects),
maintainers: boardMaintainers,
kernel_branches: kernelBranches,
Expand Down
1 change: 1 addition & 0 deletions apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"embla-carousel-react": "^8.6.0",
"jose": "^6.0.0",
"lucide-react": "^1.7.0",
"marked": "18.1.3",
"motion": "^12.38.0",
"next": "^16.4.5",
"next-intl": "^4.9.2",
Expand Down
75 changes: 62 additions & 13 deletions apps/www/src/app/(frontend)/[locale]/boards/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import {
ARMBIAN_URLS,
vendorLogoUrl,
formatBytes,
boardInstructionsSourceUrl,
} from '@armbian/config';
import { ApiClientError } from '@armbian/api-client';
import { DonationBanner } from '@/components/board/donation-banner';
import { BoardJsonLd } from '@/components/board/board-jsonld';
import { BoardImage as BoardImageWithFallback } from '@/components/board/board-image';
import { Link } from '@/i18n/navigation';
import type { BoardSummary, Image as BoardImage } from '@armbian/schemas';
import { Download, BookOpen, Code, ArrowRight, ArrowLeft } from 'lucide-react';
import { Download, BookOpen, Code, ArrowRight, ArrowLeft, ArrowDown } from 'lucide-react';
import { SiGithub } from '@icons-pack/react-simple-icons';
import type { Metadata } from 'next';
import { BoardPageDownloads } from '@/components/board/board-page-downloads';
Expand All @@ -28,6 +29,7 @@ import { SiblingBoardsCarousel } from '@/components/board/sibling-boards-carouse
import { getPayload } from 'payload';
import config from '@payload-config';
import { renderLexicalContent } from '@/lib/cms-lexical';
import { loadBoardInstructions } from '@/lib/board-instructions';

export const dynamic = 'force-dynamic';

Expand Down Expand Up @@ -181,17 +183,18 @@ export default async function BoardPage({ params }: Props) {
throw err;
}

// Sibling boards (for the "More from X" carousel) and the Payload flash
// guide both depend only on `board` and are independent — fire them in
// parallel to save a round trip on every page render.
const [siblingResult, flashGuideResult] = await Promise.allSettled([
// Sibling boards (for the "More from X" carousel), the repo install
// instructions and the Payload flash guide all depend only on `board` and
// are independent — fire them in parallel to save round trips.
const [siblingResult, instructionsResult, flashGuideResult] = await Promise.allSettled([
api.getBoards({
vendor: board.vendor_slug,
sort: 'popularity',
// 13 = 12 siblings the carousel can show + room to filter out the
// current board if it appears in the popularity ordering.
limit: 13,
}),
loadBoardInstructions(board.instructions_url),
(async () => {
const payload = await getPayload({ config });
return payload.find({
Expand All @@ -211,8 +214,14 @@ export default async function BoardPage({ params }: Props) {
siblingBoards = siblingResult.value.data.filter((b) => b.slug !== board.slug).slice(0, 12);
}

// Install instructions from armbian/armbian.github.io/board-instructions are
// the source of truth. The CMS flash guide is only a fallback for boards
// that have no instructions in the repository yet.
const instructionsHtml =
instructionsResult.status === 'fulfilled' ? instructionsResult.value : null;

let flashGuide: { title: string; content: string; prerequisites: string[] } | null = null;
if (flashGuideResult.status === 'fulfilled') {
if (!instructionsHtml && flashGuideResult.status === 'fulfilled') {
const doc = flashGuideResult.value.docs[0];
if (doc) {
const prereqs = Array.isArray(doc.prerequisites)
Expand Down Expand Up @@ -381,13 +390,24 @@ export default async function BoardPage({ params }: Props) {
<span className="flex-1">{t('build_docs')}</span>
<ArrowRight size={12} strokeWidth={2} className="opacity-30 shrink-0" />
</a>
{flashGuide && (
<FlashGuideModal
title={flashGuide.title}
content={flashGuide.content}
prerequisites={flashGuide.prerequisites}
buttonLabel={t('flash_guide')}
/>
{instructionsHtml ? (
<a
href="#instructions"
className="flex items-center gap-3 px-4 py-3 text-sm font-medium text-[rgb(var(--fg-2))] transition-colors hover:bg-[rgb(var(--bg-sub))] hover:text-[rgb(var(--fg))] border-t border-[rgb(var(--border)/0.3)]"
>
<BookOpen size={16} strokeWidth={1.5} className="opacity-50 shrink-0" />
<span className="flex-1">{t('flash_guide')}</span>
<ArrowDown size={12} strokeWidth={2} className="opacity-30 shrink-0" />
</a>
) : (
flashGuide && (
<FlashGuideModal
title={flashGuide.title}
content={flashGuide.content}
prerequisites={flashGuide.prerequisites}
buttonLabel={t('flash_guide')}
/>
)
)}
</div>
</div>
Expand All @@ -404,6 +424,35 @@ export default async function BoardPage({ params }: Props) {
boardGithubUrl={board.github_url ?? undefined}
/>

{instructionsHtml && (
<ScrollReveal>
<section id="instructions" className="mb-20 scroll-mt-16">
<div className="rounded-2xl border border-[rgb(var(--border)/0.5)] overflow-hidden bg-[rgb(var(--bg-el)/0.3)]">
<div className="flex items-center gap-3 px-6 py-5 border-b border-[rgb(var(--border)/0.3)]">
<div className="w-10 h-10 rounded-xl bg-[rgb(var(--brand)/0.1)] flex items-center justify-center shrink-0">
<BookOpen size={18} strokeWidth={2} stroke="rgb(var(--brand))" />
</div>
<h2 className="text-lg font-bold flex-1">{t('flash_guide')}</h2>
<a
href={boardInstructionsSourceUrl(board.slug)}
target="_blank"
rel="noopener noreferrer"
className="text-sm font-medium text-[rgb(var(--brand))] hover:underline inline-flex items-center gap-1.5 shrink-0"
>
<SiGithub size={14} />
{t('github')}
</a>
</div>
{/* instructionsHtml is sanitized in loadBoardInstructions() */}
<div
className="px-6 py-6 prose prose-sm dark:prose-invert max-w-none prose-code:before:content-none prose-code:after:content-none"
dangerouslySetInnerHTML={{ __html: instructionsHtml }}
/>
</div>
</section>
</ScrollReveal>
)}

{board.build_command && (
<ScrollReveal>
<section className="mb-20">
Expand Down
44 changes: 44 additions & 0 deletions apps/www/src/lib/board-instructions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Marked } from 'marked';
import { ARMBIAN_URLS } from '@armbian/config';
import { sanitizeCmsHtml } from './sanitize';

const FETCH_TIMEOUT_MS = 5_000;
/** Instructions change rarely; let Next's data cache serve them for an hour. */
const REVALIDATE_SECONDS = 3_600;
const ALLOWED_ORIGIN = new URL(ARMBIAN_URLS.CDN).origin;

const marked = new Marked({ gfm: true, async: false });

/**
* Fetch a board's Markdown install instructions (published from
* armbian/armbian.github.io/board-instructions) and render them to sanitized
* HTML. Returns null when the URL is missing, off the Armbian CDN, or the
* fetch fails, so the board page simply omits the section.
*/
export async function loadBoardInstructions(
url: string | null | undefined,
): Promise<string | null> {
if (!url) return null;
let parsed: URL;
try {
parsed = new URL(url);
} catch {
return null;
}
// The URL comes from upstream data; only fetch from our own CDN.
if (parsed.origin !== ALLOWED_ORIGIN) return null;

try {
const res = await fetch(parsed, {
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
next: { revalidate: REVALIDATE_SECONDS },
});
if (!res.ok) return null;
const markdown = await res.text();
if (!markdown.trim()) return null;
const html = sanitizeCmsHtml(marked.parse(markdown) as string, { externalLinksInNewTab: true });
return html.trim() ? html : null;
} catch {
return null;
}
}
18 changes: 17 additions & 1 deletion apps/www/src/lib/sanitize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sanitizeHtml from 'sanitize-html';

export function sanitizeCmsHtml(html: string): string {
interface SanitizeOptions {
/** Open absolute http(s) links in a new tab with a safe `rel`. */
externalLinksInNewTab?: boolean;
}

export function sanitizeCmsHtml(html: string, options: SanitizeOptions = {}): string {
return sanitizeHtml(html, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat([
'img',
Expand All @@ -27,5 +32,16 @@ export function sanitizeCmsHtml(html: string): string {
a: ['href', 'target', 'rel'],
},
allowedSchemes: ['https', 'mailto'],
transformTags: options.externalLinksInNewTab
? {
a: (tagName, attribs) =>
/^https?:\/\//i.test(attribs['href'] ?? '')
? {
tagName,
attribs: { ...attribs, target: '_blank', rel: 'noopener noreferrer' },
}
: { tagName, attribs },
}
: undefined,
});
}
5 changes: 5 additions & 0 deletions packages/config/src/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,8 @@ export function boardForumUrl(slug: string): string {
export function buildCommand(slug: string): string {
return `./compile.sh BOARD=${slug} RELEASE=trixie BUILD_DESKTOP=no BUILD_MINIMAL=yes KERNEL_CONFIGURE=no`;
}

/** Source of a board's install instructions in armbian/armbian.github.io (for "edit" links). */
export function boardInstructionsSourceUrl(slug: string): string {
return `${ARMBIAN_URLS.GITHUB_ORG}/armbian.github.io/blob/main/board-instructions/${slug}.md`;
}
2 changes: 2 additions & 0 deletions packages/schemas/src/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export const BoardDetailSchema = BoardSummarySchema.extend({
forum_url: z.string().url(),
github_url: z.string().url().nullable(),
build_command: z.string().nullable(),
/** Markdown install instructions from armbian.github.io/board-instructions, or null. */
instructions_url: z.string().url().nullable().default(null),
legacy_paths: z.array(z.string()).default([]),
maintainers: z.array(BoardMaintainerSchema).default([]),
kernel_branches: z.array(KernelBranchInfoSchema).default([]),
Expand Down
2 changes: 2 additions & 0 deletions packages/schemas/src/raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const RawImageAssetSchema = z.object({
company_name: z.string(),
company_website: z.string(),
company_logo: z.string(),
/** Absolute URL of the board's install-instructions Markdown, or '' when none exists. */
board_instructions: z.string().optional(),
armbian_version: z.string(),
file_url: z.string(),
file_url_asc: z.string(),
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading