Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

help-beta: Set first paragraph of content as meta.description.

Shubham Padia070b94aabc4c
diff --git a/help-beta/astro.config.mjs b/help-beta/astro.config.mjs
index fb33a425d0c..5ecfeec1382 100644
--- a/help-beta/astro.config.mjs
+++ b/help-beta/astro.config.mjs
@@ -67,6 +67,7 @@ export default defineConfig({
Head: "./src/components/Head.astro",
},
pagination: false,
+ routeMiddleware: "./src/route_data.ts",
customCss: ["./src/styles/main.css", "./src/styles/steps.css"],
sidebar: [
{
diff --git a/help-beta/package.json b/help-beta/package.json
index 76da7db7ff4..82485664c0e 100644
--- a/help-beta/package.json
+++ b/help-beta/package.json
@@ -17,8 +17,15 @@
"astro": "^5.1.2",
"hast-util-from-html": "^2.0.3",
"hast-util-to-html": "^9.0.5",
+ "mdast-util-to-string": "^4.0.0",
+ "remark": "^15.0.1",
+ "remark-mdx": "^3.1.0",
"sharp": "^0.34.1",
"typescript": "^5.4.5",
+ "unist-util-visit": "^5.0.0",
"unplugin-icons": "^22.1.0"
+ },
+ "devDependencies": {
+ "@types/mdast": "^4.0.4"
}
}
diff --git a/help-beta/src/route_data.ts b/help-beta/src/route_data.ts
new file mode 100644
index 00000000000..544109a1877
--- /dev/null
+++ b/help-beta/src/route_data.ts
@@ -0,0 +1,36 @@
+import assert from "node:assert";
+
+import {defineRouteMiddleware} from "@astrojs/starlight/route-data";
+import type {Paragraph} from "mdast";
+import {toString} from "mdast-util-to-string";
+import {remark} from "remark";
+import remarkMdx from "remark-mdx";
+import {visit} from "unist-util-visit";
+
+function extractFirstParagraph(content: string): string | undefined {
+ const tree = remark().use(remarkMdx).parse(content);
+
+ let firstParagraph: string | undefined;
+
+ visit(tree, "paragraph", (node: Paragraph) => {
+ if (!firstParagraph) {
+ // We need to convert the node to string so that links, emphasis, etc.
+ // are converted to plain text.
+ firstParagraph = toString(node);
+ firstParagraph = firstParagraph.replaceAll(/\s+/g, " ").trim();
+ }
+ });
+
+ return firstParagraph;
+}
+
+export const onRequest = defineRouteMiddleware((context) => {
+ assert.ok(typeof context.locals.starlightRoute.entry.body === "string");
+ context.locals.starlightRoute.head.push({
+ tag: "meta",
+ attrs: {
+ name: "description",
+ content: extractFirstParagraph(context.locals.starlightRoute.entry.body),
+ },
+ });
+});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ddd8163fded..f922e41552f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -539,15 +539,31 @@ importers:
hast-util-to-html:
specifier: ^9.0.5
version: 9.0.5
+ mdast-util-to-string:
+ specifier: ^4.0.0
+ version: 4.0.0
+ remark:
+ specifier: ^15.0.1
+ version: 15.0.1
+ remark-mdx:
+ specifier: ^3.1.0
+ version: 3.1.0
sharp:
specifier: ^0.34.1
version: 0.34.2
typescript:
specifier: ^5.4.5
version: 5.8.3
+ unist-util-visit:
+ specifier: ^5.0.0
+ version: 5.0.0
unplugin-icons:
specifier: ^22.1.0
version: 22.1.0
+ devDependencies:
+ '@types/mdast':
+ specifier: ^4.0.4
+ version: 4.0.4
packages:
@@ -7921,6 +7937,9 @@ packages:
resolution: {integrity: sha512-1OSmLd3awB/t8qdoEOMazZkNsfVTeY4fTsgzcQFdXNq8ToTN4ZGwrMnlda4K6smTFKD+GRV6O48i6Z4iKgPPpw==}
+ resolution: {integrity: sha512-Eht5w30ruCXgFmxVUSlNWQ9iiimq07URKeFS3hNc8cUWy1llX4KDWfyEDZRycMc+znsN9Ux5/tJ/BFdgdOwA3A==}
+
resolution: {integrity: sha512-8v2rWhaakv18qcvNeli2mZ/TMTL2nEyAKRvzo1WtnZBl15SHyEhrCu2/xKlJyUFKHiHgfXIyuY6g2dObJJycXQ==}
engines: {node: '>=0.10.0'}
@@ -18663,6 +18682,15 @@ snapshots:
mdast-util-to-markdown: 2.1.2
unified: 11.0.5
+ dependencies:
+ '@types/mdast': 4.0.4
+ remark-parse: 11.0.0
+ remark-stringify: 11.0.0
+ unified: 11.0.5
+ transitivePeerDependencies:
+ - supports-color
+
dependencies:
is-buffer: 1.1.6
diff --git a/version.py b/version.py
index b483c112b1d..7944fa03a9c 100644
--- a/version.py
+++ b/version.py
@@ -49,4 +49,4 @@ API_FEATURE_LEVEL = 406
# historical commits sharing the same major version, in which case a
# minor version bump suffices.
-PROVISION_VERSION = (334, 0) # bumped 2025-07-14 to upgrade Python requirements
+PROVISION_VERSION = (334, 1) # bumped 2025-07-16 to add some remark libraries