Taxonomien klassifizieren Inhalte. EmDash bringt Kategorien und Tags mit und unterstützt eigene Taxonomien.
Eingebaute Taxonomien
| Taxonomie | Typ | Beschreibung |
|---|---|---|
| Kategorien | Hierarchisch | Verschachtelung mit Eltern-Kind-Beziehungen |
| Tags | Flach | Einfache Labels ohne Hierarchie |
Standardmäßig für die Collection posts verfügbar.
Begriffe verwalten
Begriff anlegen
Admin Dashboard
-
Taxonomie-Seite öffnen (z. B.
/_emdash/admin/taxonomies/category) -
Begriffsname im Formular Add New eintragen
-
Optional:
- Slug — URL-Kennung (oft automatisch)
- Parent — bei hierarchischen Taxonomien
- Description — Beschreibung
-
Add klicken
Content Editor
-
Eintrag im Editor öffnen
-
Taxonomie-Panel in der Seitenleiste
-
Kategorien: Checkboxen oder + Add New
-
Tags: Namen kommagetrennt eingeben
-
Speichern
API
POST /_emdash/api/taxonomies/category/terms
Content-Type: application/json
Authorization: Bearer YOUR_API_TOKEN
{
"slug": "tutorials",
"label": "Tutorials",
"parentId": "term_abc",
"description": "How-to guides and tutorials"
} Begriff bearbeiten
- Taxonomie-Begriffsseite öffnen
- Edit neben dem Begriff
- Name, Slug, Parent oder Beschreibung anpassen
- Save
Begriff löschen
- Taxonomie-Begriffsseite
- Delete
- Bestätigen
Taxonomien abfragen
Alle Begriffe
import { getTaxonomyTerms } from "emdash";
const categories = await getTaxonomyTerms("category");
const tags = await getTaxonomyTerms("tag");
Hierarchisch: children-Array:
interface TaxonomyTerm {
id: string;
name: string;
slug: string;
label: string;
parentId?: string;
description?: string;
children: TaxonomyTerm[];
count?: number;
}
Einzelner Begriff
import { getTerm } from "emdash";
const category = await getTerm("category", "news");
Begriffe eines Eintrags
import { getEntryTerms } from "emdash";
const categories = await getEntryTerms("posts", "post-123", "category");
const tags = await getEntryTerms("posts", "post-123", "tag");
Inhalte nach Begriff filtern
import { getEmDashCollection } from "emdash";
const { entries: newsPosts } = await getEmDashCollection("posts", {
status: "published",
where: { category: "news" },
});
const { entries: jsPosts } = await getEmDashCollection("posts", {
status: "published",
where: { tag: "javascript" },
});
Oder:
import { getEntriesByTerm } from "emdash";
const newsPosts = await getEntriesByTerm("posts", "category", "news");
Taxonomie-Seiten
Kategorie-Archiv
---
import { getTaxonomyTerms, getTerm, getEmDashCollection } from "emdash";
import Base from "../../layouts/Base.astro";
export async function getStaticPaths() {
const categories = await getTaxonomyTerms("category");
function flatten(terms) {
return terms.flatMap((term) => [term, ...flatten(term.children)]);
}
return flatten(categories).map((cat) => ({
params: { slug: cat.slug },
props: { category: cat },
}));
}
const { category } = Astro.props;
const { entries: posts } = await getEmDashCollection("posts", {
status: "published",
where: { category: category.slug },
});
---
<Base title={category.label}>
<h1>{category.label}</h1>
{category.description && <p>{category.description}</p>}
<p>{category.count} Beiträge</p>
<ul>
{posts.map((post) => (
<li>
<a href={`/blog/${post.data.slug}`}>{post.data.title}</a>
</li>
))}
</ul>
</Base>
Tag-Archiv
---
import { getTaxonomyTerms, getEmDashCollection } from "emdash";
import Base from "../../layouts/Base.astro";
export async function getStaticPaths() {
const tags = await getTaxonomyTerms("tag");
return tags.map((tag) => ({
params: { slug: tag.slug },
props: { tag },
}));
}
const { tag } = Astro.props;
const { entries: posts } = await getEmDashCollection("posts", {
status: "published",
where: { tag: tag.slug },
});
---
<Base title={`Posts tagged "${tag.label}"`}>
<h1>#{tag.label}</h1>
<ul>
{posts.map((post) => (
<li>
<a href={`/blog/${post.data.slug}`}>{post.data.title}</a>
</li>
))}
</ul>
</Base>
Kategorieliste
---
import { getTaxonomyTerms } from "emdash";
const categories = await getTaxonomyTerms("category");
---
<nav class="category-list">
<h3>Kategorien</h3>
<ul>
{categories.map((cat) => (
<li>
<a href={`/category/${cat.slug}`}>
{cat.label} ({cat.count})
</a>
{cat.children.length > 0 && (
<ul>
{cat.children.map((child) => (
<li>
<a href={`/category/${child.slug}`}>
{child.label} ({child.count})
</a>
</li>
))}
</ul>
)}
</li>
))}
</ul>
</nav>
Tag-Cloud
---
import { getTaxonomyTerms } from "emdash";
const tags = await getTaxonomyTerms("tag");
const counts = tags.map((t) => t.count ?? 0);
const maxCount = Math.max(...counts, 1);
const minSize = 0.8;
const maxSize = 2;
function getSize(count: number) {
const ratio = count / maxCount;
return minSize + ratio * (maxSize - minSize);
}
---
<div class="tag-cloud">
{tags.map((tag) => (
<a
href={`/tag/${tag.slug}`}
style={`font-size: ${getSize(tag.count ?? 0)}rem`}
>
{tag.label}
</a>
))}
</div>
Begriffe am Inhalt anzeigen
---
import { getEntryTerms } from "emdash";
interface Props {
collection: string;
entryId: string;
}
const { collection, entryId } = Astro.props;
const categories = await getEntryTerms(collection, entryId, "category");
const tags = await getEntryTerms(collection, entryId, "tag");
---
<div class="post-terms">
{categories.length > 0 && (
<div class="categories">
<span>In:</span>
{categories.map((cat, i) => (
<>
{i > 0 && ", "}
<a href={`/category/${cat.slug}`}>{cat.label}</a>
</>
))}
</div>
)}
{tags.length > 0 && (
<div class="tags">
{tags.map((tag) => (
<a href={`/tag/${tag.slug}`} class="tag">
#{tag.label}
</a>
))}
</div>
)}
</div>
Benutzerdefinierte Taxonomien
Anlegen
POST /_emdash/api/taxonomies
Content-Type: application/json
Authorization: Bearer YOUR_API_TOKEN
{
"name": "genre",
"label": "Genres",
"labelSingular": "Genre",
"hierarchical": true,
"collections": ["books", "movies"]
}
Nutzung
import { getTaxonomyTerms, getEmDashCollection } from "emdash";
const genres = await getTaxonomyTerms("genre");
const { entries: sciFiBooks } = await getEmDashCollection("books", {
where: { genre: "science-fiction" },
});
Collections zuordnen
{
"name": "difficulty",
"label": "Difficulty Levels",
"hierarchical": false,
"collections": ["recipes", "tutorials"]
}
Taxonomie-API (REST)
| Endpoint | Methode | Beschreibung |
|---|---|---|
/_emdash/api/taxonomies | GET | Taxonomien auflisten |
/_emdash/api/taxonomies | POST | Taxonomie anlegen |
/_emdash/api/taxonomies/:name/terms | GET | Begriffe auflisten |
/_emdash/api/taxonomies/:name/terms | POST | Begriff anlegen |
/_emdash/api/taxonomies/:name/terms/:slug | GET | Begriff abrufen |
/_emdash/api/taxonomies/:name/terms/:slug | PUT | Begriff aktualisieren |
/_emdash/api/taxonomies/:name/terms/:slug | DELETE | Begriff löschen |
Begriffe zuweisen
POST /_emdash/api/content/posts/post-123/terms/category
Content-Type: application/json
Authorization: Bearer YOUR_API_TOKEN
{
"termIds": ["term_news", "term_featured"]
}