Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(website): reimplement download button
Elian Doran68ef6ea14222
diff --git a/apps/website2/src/index.html b/apps/website2/src/index.htmlindex c11245d24b..1783f2f36e 100644--- a/apps/website2/src/index.html+++ b/apps/website2/src/index.html@@ -9,10 +9,7 @@<body><header><nav>- <a class="download-button" href="https://github.com/TriliumNext/Trilium/releases/latest">- Download now- <span class="platform"></span>- </a>+</nav></div></header>diff --git a/apps/website3/src/components/DownloadButton.tsx b/apps/website3/src/components/DownloadButton.tsxnew file mode 100644index 0000000000..38edec974b--- /dev/null+++ b/apps/website3/src/components/DownloadButton.tsx@@ -0,0 +1,17 @@+import { useLayoutEffect } from "preact/hooks";+import { getRecommendedDownload } from "../download-helper";++interface DownloadButtonProps {+ big?: boolean;+}++const { architecture, platform, url } = getRecommendedDownload();++export default function DownloadButton({ big }: DownloadButtonProps) {+ return (+ <a className={`download-button ${big ? "big" : ""}`} href={url}>+ Download now{" "}+ <span class="platform">{platform} {architecture}</span>+ </a>+ )+}diff --git a/apps/website3/src/components/Header.tsx b/apps/website3/src/components/Header.tsxindex 033ffcb128..f6eb0598cd 100644--- a/apps/website3/src/components/Header.tsx+++ b/apps/website3/src/components/Header.tsx@@ -1,4 +1,5 @@import { useLocation } from 'preact-iso';+import DownloadButton from './DownloadButton';export function Header() {const { url } = useLocation();@@ -16,6 +17,8 @@ export function Header() {404</a></nav>++ <DownloadButton /></div></header>);diff --git a/apps/website2/src/script.ts b/apps/website3/src/download-helper.tssimilarity index 87%rename from apps/website2/src/script.tsrename to apps/website3/src/download-helper.tsindex 8e0592ba56..40887c9462 100644--- a/apps/website2/src/script.ts+++ b/apps/website3/src/download-helper.ts@@ -1,18 +1,20 @@-type App = "desktop" | "server";+import rootPackageJson from '../../../package.json';-type Architecture = 'x64' | 'arm64';+export type App = "desktop" | "server";-type Platform = "macos" | "windows" | "linux" | "pikapod";+export type Architecture = 'x64' | 'arm64';-const version = "0.99.0";+export type Platform = "macos" | "windows" | "linux" | "pikapod";-interface DownloadInfo {+const version = rootPackageJson.version;++export interface DownloadInfo {recommended?: boolean;name: string;url?: string;}-interface DownloadMatrixEntry {+export interface DownloadMatrixEntry {title: Record<Architecture, string> | string;description: Record<Architecture, string> | string;downloads: Record<string, DownloadInfo>;@@ -21,7 +23,7 @@ interface DownloadMatrixEntry {type DownloadMatrix = Record<App, { [ P in Platform ]?: DownloadMatrixEntry }>;// Keep compatibility info inline with https://github.com/electron/electron/blob/main/README.md#platform-support.-const downloadMatrix: DownloadMatrix = {+export const downloadMatrix: DownloadMatrix = {desktop: {windows: {title: {@@ -145,7 +147,7 @@ const downloadMatrix: DownloadMatrix = {}};-function buildDownloadUrl(app: App, platform: Platform, format: string, architecture: Architecture): string {+export function buildDownloadUrl(app: App, platform: Platform, format: string, architecture: Architecture): string {if (app === "desktop") {return downloadMatrix.desktop[platform]?.downloads[format].url ??`https://github.com/TriliumNext/Trilium/releases/download/v${version}/TriliumNotes-v${version}-${platform}-${architecture}.${format}`;@@ -156,7 +158,7 @@ function buildDownloadUrl(app: App, platform: Platform, format: string, architec}}-function getArchitecture(): Architecture {+export function getArchitecture(): Architecture {const userAgent = navigator.userAgent.toLowerCase();if (userAgent.includes('arm64') || userAgent.includes('aarch64')) {return 'arm64';@@ -176,7 +178,7 @@ function getPlatform(): Platform {}}-function getRecommendedDownload() {+export function getRecommendedDownload() {const architecture = getArchitecture();const platform = getPlatform();@@ -191,18 +193,3 @@ function getRecommendedDownload() {url}}--function applyAutomaticDownloadButtons() {- const buttons = document.querySelectorAll<HTMLLinkElement>(".download-button");- const { url, architecture, platform } = getRecommendedDownload();-- for (const button of buttons) {- button.href = url;-- const platformEl = button.querySelector(".platform");- if (!platformEl) continue;- platformEl.textContent = [ architecture, platform ].join(" ");- }-}--applyAutomaticDownloadButtons();diff --git a/apps/website3/src/pages/Home/index.tsx b/apps/website3/src/pages/Home/index.tsxindex fb7f991188..85bee33a68 100644--- a/apps/website3/src/pages/Home/index.tsx+++ b/apps/website3/src/pages/Home/index.tsx@@ -1,6 +1,7 @@import { ComponentChildren } from 'preact';import Card from '../../components/Card';import Section from '../../components/Section';+import DownloadButton from '../../components/DownloadButton';export function Home() {return (@@ -9,10 +10,7 @@ export function Home() {<div class="title-section"><h1>Organize your thoughts. Build your personal knowledge base.</h1><p>Trilium is an open-source solution for note-taking and organizing a personal knowledge base. Use it locally on your desktop, or sync it with your self-hosted server to keep your notes everywhere you go.</p>- <a class="download-button" href="https://github.com/TriliumNext/Trilium/releases/latest">- Download now- <span class="platform"></span>- </a>+ <DownloadButton big /></div><figure class="image"><img src="./src/assets/screenshot_desktop_win.png" /></figure>diff --git a/apps/website3/src/style.css b/apps/website3/src/style.cssindex 558ad1062c..44bba077a5 100644--- a/apps/website3/src/style.css+++ b/apps/website3/src/style.css@@ -229,7 +229,7 @@ span.text-big {opacity: 0.75;}-.hero-section .download-button {+.download-button.big {padding: 1em 2em;margin: 1em 0;}