Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
610ab6fdf5 | ||
|
|
81275c0395 | ||
|
|
4a46651839 | ||
|
|
e7f06548fb | ||
|
|
e2a703fc72 | ||
|
|
de75d8374d |
Vendored
+76
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Starter stylesheet for a sitemap served via buildSitemapXml({ cssUrl }).
|
||||||
|
* Uses type="text/css" on XML (W3C "Associating Style Sheets with XML") — NOT
|
||||||
|
* XSLT, so no browser deprecation warning. Selectors are the XML tag names.
|
||||||
|
*
|
||||||
|
* Copy to your project's /public/sitemap.css and adjust colors/spacing to taste.
|
||||||
|
* Crawlers ignore this; it only affects the human-readable browser view.
|
||||||
|
*/
|
||||||
|
|
||||||
|
urlset {
|
||||||
|
display: block;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
background: #090d16;
|
||||||
|
color: #f1f5f9;
|
||||||
|
padding: 2rem 1.5rem;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Each URL entry as a card. */
|
||||||
|
url {
|
||||||
|
display: block;
|
||||||
|
background: #111827;
|
||||||
|
border: 1px solid #1e293b;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem 1.25rem;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The URL itself. */
|
||||||
|
loc {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #f97316;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Metadata line: lastmod / changefreq / priority, each with a label. */
|
||||||
|
lastmod,
|
||||||
|
changefreq,
|
||||||
|
priority {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: #94a3b8;
|
||||||
|
margin-right: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastmod::before {
|
||||||
|
content: 'Ostatnia modyfikacja: ';
|
||||||
|
color: #64748b;
|
||||||
|
}
|
||||||
|
|
||||||
|
changefreq::before {
|
||||||
|
content: 'Częstotliwość: ';
|
||||||
|
color: #64748b;
|
||||||
|
}
|
||||||
|
|
||||||
|
priority::before {
|
||||||
|
content: 'Priorytet: ';
|
||||||
|
color: #64748b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* hreflang alternates as small pills. */
|
||||||
|
link {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
background: #1e293b;
|
||||||
|
color: #38bdf8;
|
||||||
|
border: 1px solid #334155;
|
||||||
|
padding: 0.15rem 0.45rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin: 0.4rem 0.35rem 0 0;
|
||||||
|
}
|
||||||
+29
-17
@@ -1,33 +1,45 @@
|
|||||||
import type { SitemapEntry } from './buildSitemapEntries.js';
|
import type { SitemapEntry } from './buildSitemapEntries.js';
|
||||||
|
type BuildSitemapXmlOptions = {
|
||||||
|
/**
|
||||||
|
* URL of a CSS stylesheet to make the sitemap readable in the browser, e.g.
|
||||||
|
* '/sitemap.css'. Uses `type="text/css"` — the W3C "Associating Style Sheets
|
||||||
|
* with XML" mechanism, which is NOT deprecated (unlike XSLT / type="text/xsl",
|
||||||
|
* which Chrome/WebKit are removing). CSS on XML shows no warning, styles the
|
||||||
|
* raw tags directly (e.g. `url { display: block }` turns the wall of text into
|
||||||
|
* cards), and crawlers ignore the directive entirely.
|
||||||
|
*/
|
||||||
|
cssUrl?: string;
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Serializes sitemap entries to an XML STRING with an XSL stylesheet reference,
|
* Serializes sitemap entries to a clean, indented XML STRING — valid for crawlers
|
||||||
* so /sitemap.xml renders as a readable table in the browser (not raw XML) while
|
* and (with `cssUrl`) styled in the browser via plain CSS.
|
||||||
* staying a valid sitemap for crawlers.
|
|
||||||
*
|
*
|
||||||
* Why this exists alongside the Next MetadataRoute sitemap: Next's app/sitemap.ts
|
* Two viewing modes:
|
||||||
* (returning SitemapEntry[]) does NOT let you inject <?xml-stylesheet?>. To get
|
* - No cssUrl → the browser's native formatted XML tree (indented, collapsible).
|
||||||
* the styled table, serve a custom route that returns this string instead:
|
* - With cssUrl → a `<?xml-stylesheet type="text/css">` directive; the project's
|
||||||
|
* CSS styles the XML tags (cards, labels via ::before). NOT XSLT — that's being
|
||||||
|
* removed from browsers and shows a deprecation warning. CSS is safe and
|
||||||
|
* W3C-standard.
|
||||||
*
|
*
|
||||||
* // app/sitemap.xml/route.ts
|
* // app/sitemap.xml/route.ts
|
||||||
* import { buildSitemapXml } from '@intecion/ipal-kit'
|
* import { buildSitemapXml } from '@intecion/ipal-kit'
|
||||||
* import { sitemap } from '@/lib/content' // your entries source
|
* import { sitemap } from '@/lib/content'
|
||||||
* export const dynamic = 'force-dynamic'
|
* export const dynamic = 'force-dynamic'
|
||||||
* export async function GET() {
|
* export async function GET() {
|
||||||
* const entries = await sitemap()
|
* const entries = await sitemap()
|
||||||
* const xml = buildSitemapXml(entries, { stylesheetUrl: '/sitemap.xsl' })
|
* const xml = buildSitemapXml(entries, { cssUrl: '/sitemap.css' })
|
||||||
* return new Response(xml, {
|
* return new Response(xml, {
|
||||||
* headers: { 'Content-Type': 'application/xml; charset=utf-8' },
|
* headers: { 'Content-Type': 'application/xml; charset=utf-8' },
|
||||||
* })
|
* })
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Put sitemap.xsl in the project's /public (copy from the plugin's assets, or
|
* Put sitemap.css in the project's /public and style the tags (see docs/seo.md
|
||||||
* serve it from a route). The <?xml-stylesheet?> points browsers at it; crawlers
|
* for a starter). Note: <loc> is an XML tag, not <a href> — CSS can't make it a
|
||||||
* ignore it and read the XML. Include hreflang alternates as <xhtml:link>.
|
* clickable link (some browsers auto-detect URLs); the win is readability, not
|
||||||
|
* clickability.
|
||||||
*
|
*
|
||||||
* NOTE: if you use this custom route, DON'T also keep app/sitemap.ts — pick one
|
* NOTE: if you use this custom route, DON'T also keep app/sitemap.ts — pick one.
|
||||||
* (the styled route OR the Next MetadataRoute). Two sitemaps at different paths
|
* Two sitemaps confuse crawlers.
|
||||||
* confuse crawlers.
|
|
||||||
*/
|
*/
|
||||||
export declare function buildSitemapXml(entries: SitemapEntry[], opts?: {
|
export declare function buildSitemapXml(entries: SitemapEntry[], opts?: BuildSitemapXmlOptions): string;
|
||||||
stylesheetUrl?: string;
|
export {};
|
||||||
}): string;
|
|
||||||
|
|||||||
Vendored
+18
-17
@@ -1,33 +1,35 @@
|
|||||||
/**
|
/**
|
||||||
* Serializes sitemap entries to an XML STRING with an XSL stylesheet reference,
|
* Serializes sitemap entries to a clean, indented XML STRING — valid for crawlers
|
||||||
* so /sitemap.xml renders as a readable table in the browser (not raw XML) while
|
* and (with `cssUrl`) styled in the browser via plain CSS.
|
||||||
* staying a valid sitemap for crawlers.
|
|
||||||
*
|
*
|
||||||
* Why this exists alongside the Next MetadataRoute sitemap: Next's app/sitemap.ts
|
* Two viewing modes:
|
||||||
* (returning SitemapEntry[]) does NOT let you inject <?xml-stylesheet?>. To get
|
* - No cssUrl → the browser's native formatted XML tree (indented, collapsible).
|
||||||
* the styled table, serve a custom route that returns this string instead:
|
* - With cssUrl → a `<?xml-stylesheet type="text/css">` directive; the project's
|
||||||
|
* CSS styles the XML tags (cards, labels via ::before). NOT XSLT — that's being
|
||||||
|
* removed from browsers and shows a deprecation warning. CSS is safe and
|
||||||
|
* W3C-standard.
|
||||||
*
|
*
|
||||||
* // app/sitemap.xml/route.ts
|
* // app/sitemap.xml/route.ts
|
||||||
* import { buildSitemapXml } from '@intecion/ipal-kit'
|
* import { buildSitemapXml } from '@intecion/ipal-kit'
|
||||||
* import { sitemap } from '@/lib/content' // your entries source
|
* import { sitemap } from '@/lib/content'
|
||||||
* export const dynamic = 'force-dynamic'
|
* export const dynamic = 'force-dynamic'
|
||||||
* export async function GET() {
|
* export async function GET() {
|
||||||
* const entries = await sitemap()
|
* const entries = await sitemap()
|
||||||
* const xml = buildSitemapXml(entries, { stylesheetUrl: '/sitemap.xsl' })
|
* const xml = buildSitemapXml(entries, { cssUrl: '/sitemap.css' })
|
||||||
* return new Response(xml, {
|
* return new Response(xml, {
|
||||||
* headers: { 'Content-Type': 'application/xml; charset=utf-8' },
|
* headers: { 'Content-Type': 'application/xml; charset=utf-8' },
|
||||||
* })
|
* })
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Put sitemap.xsl in the project's /public (copy from the plugin's assets, or
|
* Put sitemap.css in the project's /public and style the tags (see docs/seo.md
|
||||||
* serve it from a route). The <?xml-stylesheet?> points browsers at it; crawlers
|
* for a starter). Note: <loc> is an XML tag, not <a href> — CSS can't make it a
|
||||||
* ignore it and read the XML. Include hreflang alternates as <xhtml:link>.
|
* clickable link (some browsers auto-detect URLs); the win is readability, not
|
||||||
|
* clickability.
|
||||||
*
|
*
|
||||||
* NOTE: if you use this custom route, DON'T also keep app/sitemap.ts — pick one
|
* NOTE: if you use this custom route, DON'T also keep app/sitemap.ts — pick one.
|
||||||
* (the styled route OR the Next MetadataRoute). Two sitemaps at different paths
|
* Two sitemaps confuse crawlers.
|
||||||
* confuse crawlers.
|
|
||||||
*/ export function buildSitemapXml(entries, opts = {}) {
|
*/ export function buildSitemapXml(entries, opts = {}) {
|
||||||
const { stylesheetUrl } = opts;
|
const { cssUrl } = opts;
|
||||||
const esc = (s)=>s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
const esc = (s)=>s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
||||||
const urls = entries.map((e)=>{
|
const urls = entries.map((e)=>{
|
||||||
const parts = [
|
const parts = [
|
||||||
@@ -39,7 +41,6 @@
|
|||||||
}
|
}
|
||||||
if (e.changeFrequency) parts.push(` <changefreq>${e.changeFrequency}</changefreq>`);
|
if (e.changeFrequency) parts.push(` <changefreq>${e.changeFrequency}</changefreq>`);
|
||||||
if (typeof e.priority === 'number') parts.push(` <priority>${e.priority}</priority>`);
|
if (typeof e.priority === 'number') parts.push(` <priority>${e.priority}</priority>`);
|
||||||
// hreflang alternates
|
|
||||||
const alternates = e.alternates?.languages;
|
const alternates = e.alternates?.languages;
|
||||||
if (alternates) {
|
if (alternates) {
|
||||||
for (const [lang, href] of Object.entries(alternates)){
|
for (const [lang, href] of Object.entries(alternates)){
|
||||||
@@ -50,7 +51,7 @@
|
|||||||
}
|
}
|
||||||
return ` <url>\n${parts.join('\n')}\n </url>`;
|
return ` <url>\n${parts.join('\n')}\n </url>`;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
const stylesheet = stylesheetUrl ? `<?xml-stylesheet type="text/xsl" href="${esc(stylesheetUrl)}"?>\n` : '';
|
const stylesheet = cssUrl ? `<?xml-stylesheet type="text/css" href="${esc(cssUrl)}"?>\n` : '';
|
||||||
return `<?xml version="1.0" encoding="UTF-8"?>\n` + stylesheet + `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ` + `xmlns:xhtml="http://www.w3.org/1999/xhtml">\n` + urls + `\n</urlset>`;
|
return `<?xml version="1.0" encoding="UTF-8"?>\n` + stylesheet + `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ` + `xmlns:xhtml="http://www.w3.org/1999/xhtml">\n` + urls + `\n</urlset>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+72
-19
@@ -886,17 +886,17 @@ Generative Engine Optimization) i audytach „Agentic Browsing”.
|
|||||||
Wymaga wypełnionego siteDescription i sensownych meta.description stron
|
Wymaga wypełnionego siteDescription i sensownych meta.description stron
|
||||||
(inaczej llms.txt będzie ubogi).
|
(inaczej llms.txt będzie ubogi).
|
||||||
|
|
||||||
## Sitemap jako czytelna tabela (XSL stylesheet)
|
## Sitemap czytelny w przeglądarce (czysty XML)
|
||||||
|
|
||||||
Domyślny `/sitemap.xml` to surowy XML — Google go czyta, ale człowiek widzi
|
Domyślny `/sitemap.xml` (Next MetadataRoute) działa dla Google, ale w przeglądarce
|
||||||
„ścianę tagów". Można ostylować przez XSL (przeglądarka renderuje tabelę),
|
bywa nieczytelny. Możesz serwować go jako **czysty, sformatowany XML** przez
|
||||||
zachowując poprawność dla crawlerów.
|
`buildSitemapXml` — przeglądarka pokaże wbudowane drzewo XML (wcięcia, zwijanie,
|
||||||
|
kolorowanie składni), bez żadnej transformacji.
|
||||||
|
|
||||||
### Ograniczenie Next
|
> **NIE używaj XSLT.** Przeglądarki (Chrome i in.) WYCOFUJĄ XSLT — arkusz
|
||||||
|
> `<?xml-stylesheet?>` pokazuje ostrzeżenie i wkrótce przestanie działać.
|
||||||
Standardowy `app/sitemap.ts` (Next MetadataRoute) **nie pozwala** wstrzyknąć
|
> Rozwiązanie: serwuj czysty XML z poprawnym Content-Type; przeglądarka
|
||||||
`<?xml-stylesheet?>`. Żeby mieć styl, serwuj sitemap własnym route przez
|
> renderuje swój natywny widok drzewa XML sama.
|
||||||
`buildSitemapXml` (string XML z odwołaniem do XSL):
|
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
// app/sitemap.xml/route.ts (zamiast app/sitemap.ts)
|
// app/sitemap.xml/route.ts (zamiast app/sitemap.ts)
|
||||||
@@ -907,24 +907,77 @@ export const dynamic = 'force-dynamic'
|
|||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const entries = await sitemap()
|
const entries = await sitemap()
|
||||||
const xml = buildSitemapXml(entries, { stylesheetUrl: '/sitemap.xsl' })
|
const xml = buildSitemapXml(entries)
|
||||||
return new Response(xml, {
|
return new Response(xml, {
|
||||||
headers: { 'Content-Type': 'application/xml; charset=utf-8' },
|
headers: { 'Content-Type': 'application/xml; charset=utf-8' },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Plik XSL w /public
|
`buildSitemapXml` zwraca wcięty XML. Dwa tryby wyświetlania:
|
||||||
|
|
||||||
Skopiuj `sitemap.xsl` (z pluginu: `node_modules/@intecion/ipal-kit/dist/modules/seo/assets/sitemap.xsl`)
|
**Bez `cssUrl`** → przeglądarka pokazuje natywny widok drzewa XML (wcięcia, zwijanie).
|
||||||
do `public/sitemap.xsl` w projekcie. Zawiera responsywną tabelę (numer, URL,
|
|
||||||
data, języki) z dark mode. `stylesheetUrl: '/sitemap.xsl'` wskazuje na niego.
|
**Z `cssUrl`** → stylujesz XML własnym CSS (kafelki, etykiety). To W3C standard
|
||||||
|
„Associating Style Sheets with XML" — `type="text/css"`, NIE wycofywane (w
|
||||||
|
przeciwieństwie do XSLT/`text/xsl`). Zero ostrzeżenia, ładny wygląd, bezpieczne
|
||||||
|
dla Google (crawlery ignorują dyrektywę).
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const xml = buildSitemapXml(entries, { cssUrl: '/sitemap.css' })
|
||||||
|
```
|
||||||
|
|
||||||
|
### Starter CSS (public/sitemap.css)
|
||||||
|
|
||||||
|
Plugin dostarcza gotowy plik — skopiuj do projektu:
|
||||||
|
```bash
|
||||||
|
cp node_modules/@intecion/ipal-kit/dist/modules/seo/assets/sitemap.css public/sitemap.css
|
||||||
|
```
|
||||||
|
Albo skopiuj poniższy starter i dostosuj do designu. Selektory to
|
||||||
|
bezpośrednio nazwy tagów XML:
|
||||||
|
|
||||||
|
```css
|
||||||
|
/* public/sitemap.css */
|
||||||
|
urlset {
|
||||||
|
display: block;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
background: #090d16; color: #f1f5f9;
|
||||||
|
padding: 2rem 1.5rem; max-width: 1200px; margin: 0 auto;
|
||||||
|
}
|
||||||
|
url { /* każdy adres jako kafelek */
|
||||||
|
display: block;
|
||||||
|
background: #111827; border: 1px solid #1e293b; border-radius: 8px;
|
||||||
|
padding: 1rem 1.25rem; margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
loc { /* adres URL */
|
||||||
|
display: block; font-size: 0.95rem; font-weight: 600;
|
||||||
|
color: #f97316; margin-bottom: 0.5rem; word-break: break-all;
|
||||||
|
}
|
||||||
|
lastmod, changefreq, priority {
|
||||||
|
display: inline-block; font-size: 0.8rem; color: #94a3b8; margin-right: 1.5rem;
|
||||||
|
}
|
||||||
|
lastmod::before { content: 'Ostatnia modyfikacja: '; color: #64748b; }
|
||||||
|
changefreq::before { content: 'Częstotliwość: '; color: #64748b; }
|
||||||
|
priority::before { content: 'Priorytet: '; color: #64748b; }
|
||||||
|
link { /* tagi hreflang */
|
||||||
|
display: inline-block; font-size: 0.75rem;
|
||||||
|
background: #1e293b; color: #38bdf8; border: 1px solid #334155;
|
||||||
|
padding: 0.15rem 0.45rem; border-radius: 4px; margin: 0.4rem 0.35rem 0 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Kluczowe: `display: block` na `<url>`/`<loc>` zamienia „ścianę tekstu" w kafelki.
|
||||||
|
Etykiety („Ostatnia modyfikacja:") przez `::before`. Dostosuj kolory do projektu.
|
||||||
|
|
||||||
|
**Ograniczenie:** `<loc>` to tag XML, nie `<a href>` — CSS nie zrobi z niego
|
||||||
|
klikalnego linku (niektóre przeglądarki autodetektują URL). Zysk to czytelność
|
||||||
|
i organizacja, nie klikalność. Dla sitemap (głównie dla robotów) to akceptowalne.
|
||||||
|
|
||||||
### WAŻNE — jeden sitemap, nie dwa
|
### WAŻNE — jeden sitemap, nie dwa
|
||||||
|
|
||||||
Jeśli używasz route `app/sitemap.xml/route.ts` (styled), **USUŃ** `app/sitemap.ts`
|
Jeśli używasz `app/sitemap.xml/route.ts`, USUŃ `app/sitemap.ts` (MetadataRoute).
|
||||||
(MetadataRoute). Dwa sitemapy pod różnymi ścieżkami mylą crawlery. Wybierz jeden:
|
Dwa sitemapy pod różnymi ścieżkami mylą crawlery. Wybierz jeden:
|
||||||
- **styled** (`sitemap.xml/route.ts` + buildSitemapXml + XSL) — ładna tabela
|
- **route.ts + buildSitemapXml** — czytelny XML w przeglądarce
|
||||||
- **prosty** (`sitemap.ts` + reeksport z lib/content) — bez stylu, mniej kodu
|
- **sitemap.ts** (reeksport z lib/content) — mniej kodu, mniej czytelny w przeglądarce
|
||||||
|
|
||||||
Styl to kosmetyka (Google czyta oba tak samo) — rób, jeśli klient/audyt tego chce.
|
Oba tak samo dobre dla Google — to kwestia czytelności dla człowieka, nie SEO.
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@intecion/ipal-kit",
|
"name": "@intecion/ipal-kit",
|
||||||
"version": "1.4.0",
|
"version": "1.4.3",
|
||||||
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
|
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Starter stylesheet for a sitemap served via buildSitemapXml({ cssUrl }).
|
||||||
|
* Uses type="text/css" on XML (W3C "Associating Style Sheets with XML") — NOT
|
||||||
|
* XSLT, so no browser deprecation warning. Selectors are the XML tag names.
|
||||||
|
*
|
||||||
|
* Copy to your project's /public/sitemap.css and adjust colors/spacing to taste.
|
||||||
|
* Crawlers ignore this; it only affects the human-readable browser view.
|
||||||
|
*/
|
||||||
|
|
||||||
|
urlset {
|
||||||
|
display: block;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||||
|
background: #090d16;
|
||||||
|
color: #f1f5f9;
|
||||||
|
padding: 2rem 1.5rem;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Each URL entry as a card. */
|
||||||
|
url {
|
||||||
|
display: block;
|
||||||
|
background: #111827;
|
||||||
|
border: 1px solid #1e293b;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem 1.25rem;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The URL itself. */
|
||||||
|
loc {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #f97316;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Metadata line: lastmod / changefreq / priority, each with a label. */
|
||||||
|
lastmod,
|
||||||
|
changefreq,
|
||||||
|
priority {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: #94a3b8;
|
||||||
|
margin-right: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastmod::before {
|
||||||
|
content: 'Ostatnia modyfikacja: ';
|
||||||
|
color: #64748b;
|
||||||
|
}
|
||||||
|
|
||||||
|
changefreq::before {
|
||||||
|
content: 'Częstotliwość: ';
|
||||||
|
color: #64748b;
|
||||||
|
}
|
||||||
|
|
||||||
|
priority::before {
|
||||||
|
content: 'Priorytet: ';
|
||||||
|
color: #64748b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* hreflang alternates as small pills. */
|
||||||
|
link {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
background: #1e293b;
|
||||||
|
color: #38bdf8;
|
||||||
|
border: 1px solid #334155;
|
||||||
|
padding: 0.15rem 0.45rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin: 0.4rem 0.35rem 0 0;
|
||||||
|
}
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<xsl:stylesheet version="1.0"
|
|
||||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
||||||
xmlns:s="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
||||||
xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
||||||
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
|
|
||||||
<xsl:template match="/">
|
|
||||||
<html lang="pl">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8"/>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
||||||
<title>Sitemap</title>
|
|
||||||
<style>
|
|
||||||
:root { color-scheme: light dark; }
|
|
||||||
* { box-sizing: border-box; }
|
|
||||||
body {
|
|
||||||
font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
|
|
||||||
margin: 0; padding: 2rem 1rem; line-height: 1.5;
|
|
||||||
color: #1a1a1a; background: #f7f7f8;
|
|
||||||
}
|
|
||||||
.wrap { max-width: 1100px; margin: 0 auto; }
|
|
||||||
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
|
|
||||||
.meta { color: #666; font-size: .9rem; margin-bottom: 1.5rem; }
|
|
||||||
.count { font-weight: 600; }
|
|
||||||
table { width: 100%; border-collapse: collapse; background: #fff;
|
|
||||||
border-radius: .5rem; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
|
|
||||||
th, td { text-align: left; padding: .65rem .9rem; border-bottom: 1px solid #eee;
|
|
||||||
font-size: .9rem; }
|
|
||||||
th { background: #fafafa; font-weight: 600; color: #444;
|
|
||||||
position: sticky; top: 0; }
|
|
||||||
tr:last-child td { border-bottom: none; }
|
|
||||||
tr:hover td { background: #f5f8ff; }
|
|
||||||
a { color: #2563eb; text-decoration: none; word-break: break-all; }
|
|
||||||
a:hover { text-decoration: underline; }
|
|
||||||
.num { color: #999; width: 3rem; text-align: right; font-variant-numeric: tabular-nums; }
|
|
||||||
.langs { color: #666; font-size: .8rem; }
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
body { color: #e5e5e5; background: #18181b; }
|
|
||||||
table { background: #232327; box-shadow: none; }
|
|
||||||
th { background: #27272a; color: #ccc; }
|
|
||||||
th, td { border-color: #333; }
|
|
||||||
tr:hover td { background: #1e293b; }
|
|
||||||
.meta, .num, .langs { color: #888; }
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="wrap">
|
|
||||||
<h1>Mapa witryny (Sitemap)</h1>
|
|
||||||
<p class="meta">
|
|
||||||
Ten plik jest odczytywany przez wyszukiwarki.
|
|
||||||
Adresów: <span class="count"><xsl:value-of select="count(s:urlset/s:url)"/></span>
|
|
||||||
</p>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th class="num">#</th>
|
|
||||||
<th>Adres URL</th>
|
|
||||||
<th>Ostatnia zmiana</th>
|
|
||||||
<th>Języki</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<xsl:for-each select="s:urlset/s:url">
|
|
||||||
<tr>
|
|
||||||
<td class="num"><xsl:value-of select="position()"/></td>
|
|
||||||
<td>
|
|
||||||
<a href="{s:loc}"><xsl:value-of select="s:loc"/></a>
|
|
||||||
</td>
|
|
||||||
<td><xsl:value-of select="s:lastmod"/></td>
|
|
||||||
<td class="langs">
|
|
||||||
<xsl:for-each select="xhtml:link">
|
|
||||||
<xsl:value-of select="@hreflang"/>
|
|
||||||
<xsl:if test="position() != last()"><xsl:text>, </xsl:text></xsl:if>
|
|
||||||
</xsl:for-each>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</xsl:for-each>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
</xsl:template>
|
|
||||||
</xsl:stylesheet>
|
|
||||||
@@ -1,39 +1,53 @@
|
|||||||
import type { SitemapEntry } from './buildSitemapEntries.js'
|
import type { SitemapEntry } from './buildSitemapEntries.js'
|
||||||
|
|
||||||
|
type BuildSitemapXmlOptions = {
|
||||||
|
/**
|
||||||
|
* URL of a CSS stylesheet to make the sitemap readable in the browser, e.g.
|
||||||
|
* '/sitemap.css'. Uses `type="text/css"` — the W3C "Associating Style Sheets
|
||||||
|
* with XML" mechanism, which is NOT deprecated (unlike XSLT / type="text/xsl",
|
||||||
|
* which Chrome/WebKit are removing). CSS on XML shows no warning, styles the
|
||||||
|
* raw tags directly (e.g. `url { display: block }` turns the wall of text into
|
||||||
|
* cards), and crawlers ignore the directive entirely.
|
||||||
|
*/
|
||||||
|
cssUrl?: string
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes sitemap entries to an XML STRING with an XSL stylesheet reference,
|
* Serializes sitemap entries to a clean, indented XML STRING — valid for crawlers
|
||||||
* so /sitemap.xml renders as a readable table in the browser (not raw XML) while
|
* and (with `cssUrl`) styled in the browser via plain CSS.
|
||||||
* staying a valid sitemap for crawlers.
|
|
||||||
*
|
*
|
||||||
* Why this exists alongside the Next MetadataRoute sitemap: Next's app/sitemap.ts
|
* Two viewing modes:
|
||||||
* (returning SitemapEntry[]) does NOT let you inject <?xml-stylesheet?>. To get
|
* - No cssUrl → the browser's native formatted XML tree (indented, collapsible).
|
||||||
* the styled table, serve a custom route that returns this string instead:
|
* - With cssUrl → a `<?xml-stylesheet type="text/css">` directive; the project's
|
||||||
|
* CSS styles the XML tags (cards, labels via ::before). NOT XSLT — that's being
|
||||||
|
* removed from browsers and shows a deprecation warning. CSS is safe and
|
||||||
|
* W3C-standard.
|
||||||
*
|
*
|
||||||
* // app/sitemap.xml/route.ts
|
* // app/sitemap.xml/route.ts
|
||||||
* import { buildSitemapXml } from '@intecion/ipal-kit'
|
* import { buildSitemapXml } from '@intecion/ipal-kit'
|
||||||
* import { sitemap } from '@/lib/content' // your entries source
|
* import { sitemap } from '@/lib/content'
|
||||||
* export const dynamic = 'force-dynamic'
|
* export const dynamic = 'force-dynamic'
|
||||||
* export async function GET() {
|
* export async function GET() {
|
||||||
* const entries = await sitemap()
|
* const entries = await sitemap()
|
||||||
* const xml = buildSitemapXml(entries, { stylesheetUrl: '/sitemap.xsl' })
|
* const xml = buildSitemapXml(entries, { cssUrl: '/sitemap.css' })
|
||||||
* return new Response(xml, {
|
* return new Response(xml, {
|
||||||
* headers: { 'Content-Type': 'application/xml; charset=utf-8' },
|
* headers: { 'Content-Type': 'application/xml; charset=utf-8' },
|
||||||
* })
|
* })
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Put sitemap.xsl in the project's /public (copy from the plugin's assets, or
|
* Put sitemap.css in the project's /public and style the tags (see docs/seo.md
|
||||||
* serve it from a route). The <?xml-stylesheet?> points browsers at it; crawlers
|
* for a starter). Note: <loc> is an XML tag, not <a href> — CSS can't make it a
|
||||||
* ignore it and read the XML. Include hreflang alternates as <xhtml:link>.
|
* clickable link (some browsers auto-detect URLs); the win is readability, not
|
||||||
|
* clickability.
|
||||||
*
|
*
|
||||||
* NOTE: if you use this custom route, DON'T also keep app/sitemap.ts — pick one
|
* NOTE: if you use this custom route, DON'T also keep app/sitemap.ts — pick one.
|
||||||
* (the styled route OR the Next MetadataRoute). Two sitemaps at different paths
|
* Two sitemaps confuse crawlers.
|
||||||
* confuse crawlers.
|
|
||||||
*/
|
*/
|
||||||
export function buildSitemapXml(
|
export function buildSitemapXml(
|
||||||
entries: SitemapEntry[],
|
entries: SitemapEntry[],
|
||||||
opts: { stylesheetUrl?: string } = {},
|
opts: BuildSitemapXmlOptions = {},
|
||||||
): string {
|
): string {
|
||||||
const { stylesheetUrl } = opts
|
const { cssUrl } = opts
|
||||||
|
|
||||||
const esc = (s: string): string =>
|
const esc = (s: string): string =>
|
||||||
s
|
s
|
||||||
@@ -53,7 +67,6 @@ export function buildSitemapXml(
|
|||||||
}
|
}
|
||||||
if (e.changeFrequency) parts.push(` <changefreq>${e.changeFrequency}</changefreq>`)
|
if (e.changeFrequency) parts.push(` <changefreq>${e.changeFrequency}</changefreq>`)
|
||||||
if (typeof e.priority === 'number') parts.push(` <priority>${e.priority}</priority>`)
|
if (typeof e.priority === 'number') parts.push(` <priority>${e.priority}</priority>`)
|
||||||
// hreflang alternates
|
|
||||||
const alternates = e.alternates?.languages
|
const alternates = e.alternates?.languages
|
||||||
if (alternates) {
|
if (alternates) {
|
||||||
for (const [lang, href] of Object.entries(alternates)) {
|
for (const [lang, href] of Object.entries(alternates)) {
|
||||||
@@ -68,9 +81,7 @@ export function buildSitemapXml(
|
|||||||
})
|
})
|
||||||
.join('\n')
|
.join('\n')
|
||||||
|
|
||||||
const stylesheet = stylesheetUrl
|
const stylesheet = cssUrl ? `<?xml-stylesheet type="text/css" href="${esc(cssUrl)}"?>\n` : ''
|
||||||
? `<?xml-stylesheet type="text/xsl" href="${esc(stylesheetUrl)}"?>\n`
|
|
||||||
: ''
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
`<?xml version="1.0" encoding="UTF-8"?>\n` +
|
`<?xml version="1.0" encoding="UTF-8"?>\n` +
|
||||||
|
|||||||
Reference in New Issue
Block a user