bunki 0.7.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +199 -3
- package/dist/cli.js +525 -334
- package/dist/index.js +527 -336
- package/dist/utils/json-ld.d.ts +205 -0
- package/package.json +10 -10
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-LD (JavaScript Object Notation for Linked Data) utility functions
|
|
3
|
+
* for generating structured data markup for SEO optimization.
|
|
4
|
+
*
|
|
5
|
+
* This module provides functions to generate Schema.org structured data
|
|
6
|
+
* in JSON-LD format, which helps search engines better understand your content.
|
|
7
|
+
*
|
|
8
|
+
* Supported schema types:
|
|
9
|
+
* - BlogPosting: For individual blog posts/articles
|
|
10
|
+
* - WebSite: For the homepage/website metadata
|
|
11
|
+
* - BreadcrumbList: For navigation breadcrumbs
|
|
12
|
+
* - Organization: For publisher/organization information
|
|
13
|
+
* - Person: For author information
|
|
14
|
+
*
|
|
15
|
+
* @see https://schema.org/
|
|
16
|
+
* @see https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data
|
|
17
|
+
*/
|
|
18
|
+
import type { Post, SiteConfig } from "../types.js";
|
|
19
|
+
/**
|
|
20
|
+
* Base Schema.org Thing type
|
|
21
|
+
*/
|
|
22
|
+
interface SchemaOrgThing {
|
|
23
|
+
"@context": "https://schema.org";
|
|
24
|
+
"@type": string;
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for generating BlogPosting JSON-LD
|
|
29
|
+
*/
|
|
30
|
+
export interface BlogPostingOptions {
|
|
31
|
+
/** The post object */
|
|
32
|
+
post: Post;
|
|
33
|
+
/** Site configuration */
|
|
34
|
+
site: SiteConfig;
|
|
35
|
+
/** Optional image URL for the post (first image extracted from content) */
|
|
36
|
+
imageUrl?: string;
|
|
37
|
+
/** Optional date modified (defaults to date published) */
|
|
38
|
+
dateModified?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Options for generating WebSite JSON-LD
|
|
42
|
+
*/
|
|
43
|
+
export interface WebSiteOptions {
|
|
44
|
+
/** Site configuration */
|
|
45
|
+
site: SiteConfig;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Options for generating BreadcrumbList JSON-LD
|
|
49
|
+
*/
|
|
50
|
+
export interface BreadcrumbListOptions {
|
|
51
|
+
/** Site configuration */
|
|
52
|
+
site: SiteConfig;
|
|
53
|
+
/** Current post (optional, for post pages) */
|
|
54
|
+
post?: Post;
|
|
55
|
+
/** Custom breadcrumb items */
|
|
56
|
+
items?: Array<{
|
|
57
|
+
name: string;
|
|
58
|
+
url: string;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Generates a Person schema for author information
|
|
63
|
+
*
|
|
64
|
+
* @param name - Author's name
|
|
65
|
+
* @param email - Author's email (optional)
|
|
66
|
+
* @returns Person schema object
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const author = generatePersonSchema("John Doe", "john@example.com");
|
|
70
|
+
* // Returns: { "@type": "Person", "name": "John Doe", "email": "john@example.com" }
|
|
71
|
+
*/
|
|
72
|
+
export declare function generatePersonSchema(name: string, email?: string): SchemaOrgThing;
|
|
73
|
+
/**
|
|
74
|
+
* Generates an Organization schema for publisher information
|
|
75
|
+
*
|
|
76
|
+
* @param site - Site configuration
|
|
77
|
+
* @returns Organization schema object
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* const org = generateOrganizationSchema({ title: "My Blog", baseUrl: "https://example.com" });
|
|
81
|
+
* // Returns: { "@type": "Organization", "name": "My Blog", "url": "https://example.com" }
|
|
82
|
+
*/
|
|
83
|
+
export declare function generateOrganizationSchema(site: SiteConfig): SchemaOrgThing;
|
|
84
|
+
/**
|
|
85
|
+
* Generates BlogPosting structured data for a blog post
|
|
86
|
+
*
|
|
87
|
+
* This is the primary schema for individual blog posts/articles.
|
|
88
|
+
* It provides search engines with detailed information about the post
|
|
89
|
+
* including title, author, publication date, content, and more.
|
|
90
|
+
*
|
|
91
|
+
* @param options - BlogPosting generation options
|
|
92
|
+
* @returns BlogPosting schema as JSON-LD object
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* const jsonLd = generateBlogPostingSchema({
|
|
96
|
+
* post: { title: "Hello World", date: "2025-01-15T10:00:00Z", ... },
|
|
97
|
+
* site: { title: "My Blog", baseUrl: "https://example.com", ... }
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* @see https://schema.org/BlogPosting
|
|
101
|
+
*/
|
|
102
|
+
export declare function generateBlogPostingSchema(options: BlogPostingOptions): SchemaOrgThing;
|
|
103
|
+
/**
|
|
104
|
+
* Generates WebSite structured data for the homepage
|
|
105
|
+
*
|
|
106
|
+
* This schema provides search engines with information about the website
|
|
107
|
+
* itself, including name, description, and URL.
|
|
108
|
+
*
|
|
109
|
+
* @param options - WebSite generation options
|
|
110
|
+
* @returns WebSite schema as JSON-LD object
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* const jsonLd = generateWebSiteSchema({
|
|
114
|
+
* site: { title: "My Blog", baseUrl: "https://example.com", description: "..." }
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* @see https://schema.org/WebSite
|
|
118
|
+
*/
|
|
119
|
+
export declare function generateWebSiteSchema(options: WebSiteOptions): SchemaOrgThing;
|
|
120
|
+
/**
|
|
121
|
+
* Generates BreadcrumbList structured data for navigation
|
|
122
|
+
*
|
|
123
|
+
* Breadcrumbs help search engines understand the site's hierarchy
|
|
124
|
+
* and can appear in search results.
|
|
125
|
+
*
|
|
126
|
+
* @param options - BreadcrumbList generation options
|
|
127
|
+
* @returns BreadcrumbList schema as JSON-LD object
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* // For a blog post
|
|
131
|
+
* const jsonLd = generateBreadcrumbListSchema({
|
|
132
|
+
* site: { title: "My Blog", baseUrl: "https://example.com" },
|
|
133
|
+
* post: { title: "Hello World", url: "/2025/hello-world/" }
|
|
134
|
+
* });
|
|
135
|
+
*
|
|
136
|
+
* @see https://schema.org/BreadcrumbList
|
|
137
|
+
*/
|
|
138
|
+
export declare function generateBreadcrumbListSchema(options: BreadcrumbListOptions): SchemaOrgThing;
|
|
139
|
+
/**
|
|
140
|
+
* Converts a JSON-LD object to an HTML script tag string
|
|
141
|
+
*
|
|
142
|
+
* This helper function serializes the JSON-LD object and wraps it
|
|
143
|
+
* in a script tag for inclusion in HTML templates.
|
|
144
|
+
*
|
|
145
|
+
* @param jsonLd - The JSON-LD object to convert
|
|
146
|
+
* @returns HTML script tag string
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* const schema = generateBlogPostingSchema({ ... });
|
|
150
|
+
* const scriptTag = toScriptTag(schema);
|
|
151
|
+
* // Returns: '<script type="application/ld+json">{"@context":"https://schema.org",...}</script>'
|
|
152
|
+
*/
|
|
153
|
+
export declare function toScriptTag(jsonLd: SchemaOrgThing): string;
|
|
154
|
+
/**
|
|
155
|
+
* Extracts the first image URL from HTML content
|
|
156
|
+
*
|
|
157
|
+
* Searches for the first <img> tag in HTML content and returns its src attribute.
|
|
158
|
+
* This is useful for automatically finding a representative image for BlogPosting schema.
|
|
159
|
+
*
|
|
160
|
+
* @param html - HTML content to search
|
|
161
|
+
* @param baseUrl - Base URL to prepend to relative image URLs
|
|
162
|
+
* @returns Full image URL or undefined if no image found
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* const imageUrl = extractFirstImageUrl(
|
|
166
|
+
* '<p>Text</p><img src="/img/photo.jpg" alt="Photo">',
|
|
167
|
+
* 'https://example.com'
|
|
168
|
+
* );
|
|
169
|
+
* // Returns: 'https://example.com/img/photo.jpg'
|
|
170
|
+
*/
|
|
171
|
+
export declare function extractFirstImageUrl(html: string, baseUrl: string): string | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Generates multiple JSON-LD schemas for a blog post page
|
|
174
|
+
*
|
|
175
|
+
* This is a convenience function that generates all relevant schemas
|
|
176
|
+
* for a typical blog post page: BlogPosting, BreadcrumbList, and Organization.
|
|
177
|
+
*
|
|
178
|
+
* @param options - BlogPosting generation options
|
|
179
|
+
* @returns Array of JSON-LD schemas
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* const schemas = generatePostPageSchemas({
|
|
183
|
+
* post: { ... },
|
|
184
|
+
* site: { ... }
|
|
185
|
+
* });
|
|
186
|
+
* // Returns: [BlogPosting, BreadcrumbList]
|
|
187
|
+
*/
|
|
188
|
+
export declare function generatePostPageSchemas(options: BlogPostingOptions): SchemaOrgThing[];
|
|
189
|
+
/**
|
|
190
|
+
* Generates multiple JSON-LD schemas for the homepage
|
|
191
|
+
*
|
|
192
|
+
* This is a convenience function that generates all relevant schemas
|
|
193
|
+
* for the homepage: WebSite and Organization.
|
|
194
|
+
*
|
|
195
|
+
* @param options - WebSite generation options
|
|
196
|
+
* @returns Array of JSON-LD schemas
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* const schemas = generateHomePageSchemas({
|
|
200
|
+
* site: { title: "My Blog", baseUrl: "https://example.com", ... }
|
|
201
|
+
* });
|
|
202
|
+
* // Returns: [WebSite, Organization]
|
|
203
|
+
*/
|
|
204
|
+
export declare function generateHomePageSchemas(options: WebSiteOptions): SchemaOrgThing[];
|
|
205
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunki",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "An opinionated static site generator built with Bun featuring PostCSS integration and modern web development workflows",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"commander": "^14.0.2",
|
|
51
51
|
"gray-matter": "^4.0.3",
|
|
52
52
|
"highlight.js": "^11.11.1",
|
|
53
|
-
"marked": "^
|
|
54
|
-
"marked-highlight": "^2.2.
|
|
53
|
+
"marked": "^17.0.1",
|
|
54
|
+
"marked-highlight": "^2.2.3",
|
|
55
55
|
"nunjucks": "^3.2.4",
|
|
56
56
|
"postcss": "^8.5.6",
|
|
57
57
|
"postcss-cli": "^11.0.1",
|
|
@@ -59,15 +59,15 @@
|
|
|
59
59
|
"slugify": "^1.6.6"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@tailwindcss/postcss": "^4.1.
|
|
62
|
+
"@tailwindcss/postcss": "^4.1.18",
|
|
63
63
|
"@types/nunjucks": "^3.2.6",
|
|
64
64
|
"@types/sanitize-html": "^2.16.0",
|
|
65
|
-
"autoprefixer": "^10.4.
|
|
66
|
-
"bun-types": "^1.3.
|
|
65
|
+
"autoprefixer": "^10.4.23",
|
|
66
|
+
"bun-types": "^1.3.5",
|
|
67
67
|
"husky": "^9.1.7",
|
|
68
|
-
"lint-staged": "^16.2.
|
|
69
|
-
"prettier": "^3.
|
|
70
|
-
"tailwindcss": "^4.1.
|
|
68
|
+
"lint-staged": "^16.2.7",
|
|
69
|
+
"prettier": "^3.7.4",
|
|
70
|
+
"tailwindcss": "^4.1.18",
|
|
71
71
|
"typescript": "^5.9.3"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"README.md"
|
|
85
85
|
],
|
|
86
86
|
"engines": {
|
|
87
|
-
"bun": ">=1.3.
|
|
87
|
+
"bun": ">=1.3.2",
|
|
88
88
|
"node": ">=18.0.0"
|
|
89
89
|
},
|
|
90
90
|
"engineStrict": true,
|