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
1 change: 1 addition & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default defineConfig({
['meta', { httpEquiv: 'Origin-Trial', content: ORIGIN_TRIAL_WEBMCP }],
['script', { src: '/neuron-js/webmcp/webmcp.js' }],
['script', { src: '/neuron-js/webmcp/neuron-webmcp.js', defer: 'true' }],
['script', { async: 'true', src: 'https://news.google.com/swg/js/v1/publisher.js' }],
],
ignoreDeadLinks: true,
markdown: {
Expand Down
40 changes: 40 additions & 0 deletions docs/.vitepress/theme/PreferredSourceFooter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<template>
<div class="preferred-source-footer">
<div google-add-preferred-source-btn :data-theme="isDark ? 'dark' : 'light'"></div>
<p class="preferred-source-note">
Add <code>sebasoft.github.io</code> as a preferred source in Google Search — Top Stories,
AI Overviews, and AI Mode.
</p>
</div>
</template>

<script setup lang="ts">
import { useData } from "vitepress";

const { isDark } = useData();
</script>

<style scoped>
.preferred-source-footer {
align-items: center;
border-top: 1px solid var(--vp-c-divider);
display: flex;
flex-direction: column;
gap: 8px;
margin: 24px auto 0;
max-width: 768px;
padding: 16px 24px 8px;
}

.preferred-source-footer > div {
min-height: 40px;
}

.preferred-source-note {
color: var(--vp-c-text-2);
font-size: 13px;
line-height: 1.5;
margin: 0;
text-align: center;
}
</style>
10 changes: 10 additions & 0 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import DefaultTheme from "vitepress/theme";
import { inBrowser } from "vitepress";
import type { EnhanceAppContext } from "vitepress";
import { h } from "vue";
import mermaid from "mermaid";
import PreferredSourceFooter from "./PreferredSourceFooter.vue";
import "./custom.css";

const isDarkMode = () => document.documentElement.classList.contains("dark");
Expand Down Expand Up @@ -56,6 +58,11 @@ const scheduleRender = () => {

export default {
extends: DefaultTheme,
Layout() {
return h(DefaultTheme.Layout, null, {
"layout-bottom": () => h(PreferredSourceFooter),
});
},
enhanceApp({ router }: EnhanceAppContext) {
if (!inBrowser) {
return;
Expand All @@ -68,6 +75,9 @@ export default {
router.onAfterRouteChanged = async (to) => {
await afterRouteChange?.(to);
scheduleRender();
// The Google preferred-source button lives in the layout-bottom slot,
// which VitePress keeps mounted across SPA route changes; publisher.js
// initializes it once on load — verified in the browser E2E.
};
},
setup() {
Expand Down
33 changes: 33 additions & 0 deletions tests/contracts/preferred-source-footer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// NJS-SEO-6 follow-up: contract test for the Google "Add to preferred sources"
// footer button on the documentation site.
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";

const read = (path: string) => readFileSync(path, "utf8");

describe("Google preferred-source footer button", () => {
it("loads the official publisher.js in the VitePress head", () => {
expect(read("docs/.vitepress/config.ts")).toContain(
"https://news.google.com/swg/js/v1/publisher.js",
);
});

it("renders the standard button container in the layout-bottom footer", () => {
const component = read("docs/.vitepress/theme/PreferredSourceFooter.vue");
expect(component).toContain("google-add-preferred-source-btn");
expect(component).toContain("preferred-source-footer");
// theme aware: light/dark follows the site theme
expect(component).toContain("isDark");
});

it("mounts the footer via the layout-bottom slot", () => {
const theme = read("docs/.vitepress/theme/index.ts");
expect(theme).toContain("PreferredSourceFooter");
expect(theme).toContain("layout-bottom");
});

it("states the eligible source honestly (domain, not subdirectory)", () => {
const component = read("docs/.vitepress/theme/PreferredSourceFooter.vue");
expect(component).toContain("sebasoft.github.io");
});
});
Loading