eleventy-plugin-standard-site 1.0.0-rc.1
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/LICENSE +21 -0
- package/README.md +51 -0
- package/dist/index.cjs +254 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +42 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +42 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +229 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrés Ignacio Torres
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# eleventy-plugin-standard-site
|
|
2
|
+
|
|
3
|
+
[11ty](https://www.11ty.dev/) plugin to generate and publish [Standard.Site](https://standard.site/) records on your [AT Protocol](https://atproto.com/) PDS for your site.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
This project supports Node.js 18 and later. You can install the plugin from `npm`:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install eleventy-plugin-standard-site
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Add the plugin to your Eleventy configuration file, e.g.:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { pluginStandardSite } from "eleventy-plugin-standard-site";
|
|
19
|
+
|
|
20
|
+
export default function (eleventyConfig) {
|
|
21
|
+
eleventyConfig.addPlugin(pluginStandardSite, {
|
|
22
|
+
// Publication details for your site
|
|
23
|
+
publicationName: "My Site",
|
|
24
|
+
publicationDescription: "A blog where I write about my life!",
|
|
25
|
+
publicationUrl: "https://example.com",
|
|
26
|
+
// You can use your ATProto DID or handle
|
|
27
|
+
identifier: "did:plc:abc123",
|
|
28
|
+
// Please use an app-password!
|
|
29
|
+
password: "app-password-xyz",
|
|
30
|
+
|
|
31
|
+
// Optional: whether the publication should appear in discovery feeds, defaults to true
|
|
32
|
+
showInDiscover: true,
|
|
33
|
+
// Optional: PDS URL, defaults to "https://bsky.social"
|
|
34
|
+
pds: "https://bsky.social"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The plugin will get triggered on build time after Eleventy has generated the output files.
|
|
40
|
+
|
|
41
|
+
## Contributing
|
|
42
|
+
|
|
43
|
+
To set up the development environment, clone the repository and install dependencies with `npm install`. Development environment requires Node.js 22 or later.
|
|
44
|
+
|
|
45
|
+
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
|
|
46
|
+
|
|
47
|
+
Please make sure to update tests as appropriate.
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let path = require("path");
|
|
25
|
+
path = __toESM(path, 1);
|
|
26
|
+
let fs = require("fs");
|
|
27
|
+
fs = __toESM(fs, 1);
|
|
28
|
+
//#region src/types.ts
|
|
29
|
+
const ENDPOINTS = {
|
|
30
|
+
createSession: "/xrpc/com.atproto.server.createSession",
|
|
31
|
+
createRecord: "/xrpc/com.atproto.repo.createRecord",
|
|
32
|
+
putRecord: "/xrpc/com.atproto.repo.putRecord",
|
|
33
|
+
listRecords: "/xrpc/com.atproto.repo.listRecords"
|
|
34
|
+
};
|
|
35
|
+
const LEXICONS = {
|
|
36
|
+
publication: "site.standard.publication",
|
|
37
|
+
document: "site.standard.document"
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/utils.ts
|
|
41
|
+
function extractRecordKey(uri) {
|
|
42
|
+
const parts = uri.split("/");
|
|
43
|
+
return parts[parts.length - 1];
|
|
44
|
+
}
|
|
45
|
+
function normalizePdsUrl(url) {
|
|
46
|
+
let normalizedUrl = url.trim();
|
|
47
|
+
if (normalizedUrl.endsWith("/")) normalizedUrl = normalizedUrl.slice(0, -1);
|
|
48
|
+
if (normalizedUrl.length === 0) throw new Error("PDS URL cannot be empty after normalization.");
|
|
49
|
+
if (!normalizedUrl.startsWith("http://") && !normalizedUrl.startsWith("https://")) normalizedUrl = `https://${normalizedUrl}`;
|
|
50
|
+
return normalizedUrl;
|
|
51
|
+
}
|
|
52
|
+
function normalizeIdentifier(identifier) {
|
|
53
|
+
let normalizedIdentifier = identifier.trim();
|
|
54
|
+
if (normalizedIdentifier.startsWith("@")) normalizedIdentifier = normalizedIdentifier.slice(1);
|
|
55
|
+
if (normalizedIdentifier.length === 0) throw new Error("Identifier cannot be empty after normalization.");
|
|
56
|
+
return normalizedIdentifier;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/publisher.ts
|
|
60
|
+
function createPublisher({ pds, identifier, password }) {
|
|
61
|
+
if (!pds || !identifier || !password) throw new Error("Missing required PDS configuration: pds, identifier, and password are all required.");
|
|
62
|
+
const normalizedPds = normalizePdsUrl(pds);
|
|
63
|
+
const normalizedIdentifier = normalizeIdentifier(identifier);
|
|
64
|
+
const getEndpointUrl = (endpoint) => `${normalizedPds}${endpoint}`;
|
|
65
|
+
let accessJwt = null;
|
|
66
|
+
const checkSession = () => {
|
|
67
|
+
if (!accessJwt) throw new Error("Session not started. Call startSession() before making requests.");
|
|
68
|
+
};
|
|
69
|
+
const listRecords = async (collection) => {
|
|
70
|
+
const baseEndpointUrl = getEndpointUrl(ENDPOINTS.listRecords);
|
|
71
|
+
let cursor;
|
|
72
|
+
const records = [];
|
|
73
|
+
do {
|
|
74
|
+
const params = new URLSearchParams();
|
|
75
|
+
params.set("collection", collection);
|
|
76
|
+
params.set("repo", normalizedIdentifier);
|
|
77
|
+
if (cursor) params.set("cursor", cursor);
|
|
78
|
+
const url = new URL(baseEndpointUrl);
|
|
79
|
+
url.search = params.toString();
|
|
80
|
+
const response = await fetch(url.toString(), {
|
|
81
|
+
method: "GET",
|
|
82
|
+
headers: { "Content-Type": "application/json" }
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok) throw new Error(`Failed to list ${collection} records: ${response.statusText}`);
|
|
85
|
+
const data = await response.json();
|
|
86
|
+
records.push(...data.records);
|
|
87
|
+
if (data.cursor) cursor = data.cursor;
|
|
88
|
+
} while (cursor);
|
|
89
|
+
return records;
|
|
90
|
+
};
|
|
91
|
+
const getPublicationRecords = async () => {
|
|
92
|
+
try {
|
|
93
|
+
return (await listRecords(LEXICONS.publication)).map((record) => ({
|
|
94
|
+
...record.value,
|
|
95
|
+
uri: record.uri
|
|
96
|
+
}));
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.error("Error fetching publication records:", err);
|
|
99
|
+
}
|
|
100
|
+
return [];
|
|
101
|
+
};
|
|
102
|
+
const createRecord = async (collection, value) => {
|
|
103
|
+
checkSession();
|
|
104
|
+
const response = await fetch(getEndpointUrl(ENDPOINTS.createRecord), {
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers: {
|
|
107
|
+
Authorization: `Bearer ${accessJwt}`,
|
|
108
|
+
"Content-Type": "application/json"
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify({
|
|
111
|
+
collection,
|
|
112
|
+
record: value,
|
|
113
|
+
repo: normalizedIdentifier
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
if (!response.ok) throw new Error(`Failed to create record in ${collection}: ${response.statusText}`);
|
|
117
|
+
return await response.json();
|
|
118
|
+
};
|
|
119
|
+
const getSiteDocumentRecords = async (site) => {
|
|
120
|
+
try {
|
|
121
|
+
return (await listRecords(LEXICONS.document)).filter((record) => record.value.site === site).map((record) => ({
|
|
122
|
+
...record.value,
|
|
123
|
+
uri: record.uri
|
|
124
|
+
}));
|
|
125
|
+
} catch (err) {
|
|
126
|
+
console.error("Error fetching document records:", err);
|
|
127
|
+
}
|
|
128
|
+
return [];
|
|
129
|
+
};
|
|
130
|
+
const putRecord = async (collection, recordKey, value) => {
|
|
131
|
+
checkSession();
|
|
132
|
+
const response = await fetch(getEndpointUrl(ENDPOINTS.putRecord), {
|
|
133
|
+
method: "POST",
|
|
134
|
+
headers: {
|
|
135
|
+
Authorization: `Bearer ${accessJwt}`,
|
|
136
|
+
"Content-Type": "application/json"
|
|
137
|
+
},
|
|
138
|
+
body: JSON.stringify({
|
|
139
|
+
collection,
|
|
140
|
+
rkey: recordKey,
|
|
141
|
+
record: value,
|
|
142
|
+
repo: normalizedIdentifier
|
|
143
|
+
})
|
|
144
|
+
});
|
|
145
|
+
if (!response.ok) throw new Error(`Failed to update record in ${collection}: ${response.statusText}`);
|
|
146
|
+
return await response.json();
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
startSession: async () => {
|
|
150
|
+
const response = await fetch(getEndpointUrl(ENDPOINTS.createSession), {
|
|
151
|
+
method: "POST",
|
|
152
|
+
headers: { "Content-Type": "application/json" },
|
|
153
|
+
body: JSON.stringify({
|
|
154
|
+
identifier: normalizedIdentifier,
|
|
155
|
+
password
|
|
156
|
+
})
|
|
157
|
+
});
|
|
158
|
+
if (!response.ok) throw new Error(`Failed to create session: ${response.statusText}`);
|
|
159
|
+
accessJwt = (await response.json()).accessJwt;
|
|
160
|
+
},
|
|
161
|
+
createOrUpdatePublicationRecord: async (publication) => {
|
|
162
|
+
checkSession();
|
|
163
|
+
const existingRecord = (await getPublicationRecords()).find((record) => record.url === publication.url);
|
|
164
|
+
let recordUri;
|
|
165
|
+
if (existingRecord) {
|
|
166
|
+
console.log(`Existing publication record found for URL ${publication.url}, updating...`);
|
|
167
|
+
const existingRecordUri = existingRecord.uri;
|
|
168
|
+
const existingRecordKey = extractRecordKey(existingRecordUri);
|
|
169
|
+
recordUri = (await putRecord(LEXICONS.publication, existingRecordKey, publication)).uri;
|
|
170
|
+
} else {
|
|
171
|
+
console.log(`No existing publication record found for URL ${publication.url}, creating new record...`);
|
|
172
|
+
recordUri = (await createRecord(LEXICONS.publication, publication)).uri;
|
|
173
|
+
}
|
|
174
|
+
const recordKey = extractRecordKey(recordUri);
|
|
175
|
+
console.log(`Publication record for URL ${publication.url} available at URI: ${recordUri} (record key: ${recordKey})`);
|
|
176
|
+
return recordUri;
|
|
177
|
+
},
|
|
178
|
+
createOrUpdateDocumentRecord: async (document) => {
|
|
179
|
+
checkSession();
|
|
180
|
+
const existingRecord = (await getSiteDocumentRecords(document.site)).find((record) => record.path === document.path);
|
|
181
|
+
let recordUri;
|
|
182
|
+
if (existingRecord) {
|
|
183
|
+
console.log(`Existing document record found for path ${document.path}, updating...`);
|
|
184
|
+
const existingRecordUri = existingRecord.uri;
|
|
185
|
+
const existingRecordKey = extractRecordKey(existingRecordUri);
|
|
186
|
+
recordUri = (await putRecord(LEXICONS.document, existingRecordKey, document)).uri;
|
|
187
|
+
} else {
|
|
188
|
+
console.log(`No existing document record found for path ${document.path}, creating new record...`);
|
|
189
|
+
recordUri = (await createRecord(LEXICONS.document, document)).uri;
|
|
190
|
+
}
|
|
191
|
+
const recordKey = extractRecordKey(recordUri);
|
|
192
|
+
console.log(`Document record for path ${document.path} available at URI: ${recordUri} (record key: ${recordKey})`);
|
|
193
|
+
return recordUri;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/plugin.ts
|
|
199
|
+
const DEFAULT_OPTIONS = {
|
|
200
|
+
pds: "https://bsky.social",
|
|
201
|
+
showInDiscover: true,
|
|
202
|
+
standardSiteDocumentTag: "standard-site-document"
|
|
203
|
+
};
|
|
204
|
+
function pluginStandardSite(eleventyConfig, options) {
|
|
205
|
+
const resolvedOptions = {
|
|
206
|
+
...DEFAULT_OPTIONS,
|
|
207
|
+
...options
|
|
208
|
+
};
|
|
209
|
+
const documentTag = resolvedOptions.standardSiteDocumentTag ?? DEFAULT_OPTIONS.standardSiteDocumentTag;
|
|
210
|
+
let standardSiteDocumentPosts = [];
|
|
211
|
+
eleventyConfig.addCollection("standardSiteDocuments", (collection) => {
|
|
212
|
+
standardSiteDocumentPosts = collection.getFilteredByTag(documentTag);
|
|
213
|
+
return standardSiteDocumentPosts;
|
|
214
|
+
});
|
|
215
|
+
eleventyConfig.on("eleventy.after", async ({ dir }) => {
|
|
216
|
+
const publisher = createPublisher(resolvedOptions);
|
|
217
|
+
try {
|
|
218
|
+
await publisher.startSession();
|
|
219
|
+
console.log("Successfully authenticated to PDS");
|
|
220
|
+
} catch (error) {
|
|
221
|
+
console.error("Failed to authenticate to PDS:", error);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const publication = {
|
|
225
|
+
$type: LEXICONS.publication,
|
|
226
|
+
url: resolvedOptions.publicationUrl,
|
|
227
|
+
name: resolvedOptions.publicationName,
|
|
228
|
+
description: resolvedOptions.publicationDescription,
|
|
229
|
+
preferences: { showInDiscover: resolvedOptions.showInDiscover ?? DEFAULT_OPTIONS.showInDiscover }
|
|
230
|
+
};
|
|
231
|
+
const publicationRecordUri = await publisher.createOrUpdatePublicationRecord(publication);
|
|
232
|
+
const outputDir = dir.output;
|
|
233
|
+
const wellKnownEndpointPath = path.default.join(outputDir, ".well-known", LEXICONS.publication);
|
|
234
|
+
fs.default.mkdirSync(path.default.dirname(wellKnownEndpointPath), { recursive: true });
|
|
235
|
+
fs.default.writeFileSync(wellKnownEndpointPath, publicationRecordUri, "utf-8");
|
|
236
|
+
for (const post of standardSiteDocumentPosts) {
|
|
237
|
+
console.log(`Processing post: ${post.url}`);
|
|
238
|
+
const documentRecord = {
|
|
239
|
+
site: publicationRecordUri,
|
|
240
|
+
title: post.data.title,
|
|
241
|
+
publishedAt: post.date,
|
|
242
|
+
path: post.url,
|
|
243
|
+
description: post.data.description,
|
|
244
|
+
bskyPostRef: post.data.bskyPostRef
|
|
245
|
+
};
|
|
246
|
+
await publisher.createOrUpdateDocumentRecord(documentRecord);
|
|
247
|
+
}
|
|
248
|
+
console.log(`Finished processing Standard.Site records with 1 publication and ${standardSiteDocumentPosts.length} documents.`);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
//#endregion
|
|
252
|
+
exports.pluginStandardSite = pluginStandardSite;
|
|
253
|
+
|
|
254
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/types.ts","../src/utils.ts","../src/publisher.ts","../src/plugin.ts"],"sourcesContent":["export const ENDPOINTS = {\n createSession: \"/xrpc/com.atproto.server.createSession\",\n createRecord: \"/xrpc/com.atproto.repo.createRecord\",\n putRecord: \"/xrpc/com.atproto.repo.putRecord\",\n listRecords: \"/xrpc/com.atproto.repo.listRecords\"\n};\n\nexport const LEXICONS = {\n publication: \"site.standard.publication\",\n document: \"site.standard.document\"\n};\n\nexport interface PublisherOptions {\n pds?: string;\n identifier?: string;\n password?: string;\n}\n\nexport interface SessionResponse {\n accessJwt: string;\n}\n\nexport interface Record {\n cid: string;\n uri: string;\n value: object;\n}\n\nexport interface CreateOrPutRecordResponse {\n uri: string;\n cid: string;\n commit: {\n cid: string;\n rev: string;\n };\n validationStatus: string;\n}\n\nexport interface ListRecordsResponse {\n cursor: string | null;\n records: Record[];\n}\n\nexport interface Publication {\n $type: string;\n url: string;\n name: string;\n description: string;\n preferences: {\n showInDiscover: boolean;\n };\n}\n\nexport interface Document {\n site: string;\n title: string;\n publishedAt: Date;\n path?: string;\n description?: string;\n bskyPostRef?: string;\n}\n\nexport interface PublicationWithUri extends Publication {\n uri: string;\n}\n\nexport interface DocumentWithUri extends Document {\n uri: string;\n}\n\nexport interface Publisher {\n startSession: () => Promise<void>;\n createOrUpdatePublicationRecord: (publication: Publication) => Promise<string>;\n createOrUpdateDocumentRecord: (document: Document) => Promise<string>;\n}\n\nexport type StandardSitePluginOptions = Partial<PublisherOptions> & {\n publicationName: string;\n publicationDescription: string;\n publicationUrl: string;\n standardSiteDocumentTag?: string;\n showInDiscover?: boolean;\n};\n","export function extractRecordKey(uri: string): string {\n const parts = uri.split(\"/\");\n return parts[parts.length - 1];\n}\n\nexport function normalizePdsUrl(url: string): string {\n let normalizedUrl = url.trim();\n\n if (normalizedUrl.endsWith(\"/\")) {\n normalizedUrl = normalizedUrl.slice(0, -1);\n }\n\n if (normalizedUrl.length === 0) {\n throw new Error(\"PDS URL cannot be empty after normalization.\");\n }\n\n if (!normalizedUrl.startsWith(\"http://\") && !normalizedUrl.startsWith(\"https://\")) {\n normalizedUrl = `https://${normalizedUrl}`;\n }\n\n return normalizedUrl;\n}\n\nexport function normalizeIdentifier(identifier: string): string {\n let normalizedIdentifier = identifier.trim();\n\n if (normalizedIdentifier.startsWith(\"@\")) {\n normalizedIdentifier = normalizedIdentifier.slice(1);\n }\n\n if (normalizedIdentifier.length === 0) {\n throw new Error(\"Identifier cannot be empty after normalization.\");\n }\n\n return normalizedIdentifier;\n}\n","import {\n ENDPOINTS,\n LEXICONS,\n PublisherOptions,\n SessionResponse,\n Record,\n CreateOrPutRecordResponse,\n ListRecordsResponse,\n Publication,\n PublicationWithUri,\n Publisher,\n Document,\n DocumentWithUri\n} from \"./types\";\nimport { extractRecordKey, normalizePdsUrl, normalizeIdentifier } from \"./utils\";\n\nexport function createPublisher({ pds, identifier, password }: PublisherOptions): Publisher {\n if (!pds || !identifier || !password) {\n throw new Error(\n \"Missing required PDS configuration: pds, identifier, and password are all required.\"\n );\n }\n\n const normalizedPds = normalizePdsUrl(pds);\n const normalizedIdentifier = normalizeIdentifier(identifier);\n const getEndpointUrl = (endpoint: string) => `${normalizedPds}${endpoint}`;\n\n let accessJwt: string | null = null;\n const checkSession = () => {\n if (!accessJwt) {\n throw new Error(\"Session not started. Call startSession() before making requests.\");\n }\n };\n\n const listRecords = async (collection: string): Promise<Record[]> => {\n const baseEndpointUrl = getEndpointUrl(ENDPOINTS.listRecords);\n\n let cursor: string | undefined;\n const records: Record[] = [];\n do {\n const params = new URLSearchParams();\n params.set(\"collection\", collection);\n params.set(\"repo\", normalizedIdentifier);\n if (cursor) {\n params.set(\"cursor\", cursor);\n }\n\n const url = new URL(baseEndpointUrl);\n url.search = params.toString();\n\n const response = await fetch(url.toString(), {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\"\n }\n });\n\n if (!response.ok) {\n throw new Error(`Failed to list ${collection} records: ${response.statusText}`);\n }\n\n const data = (await response.json()) as ListRecordsResponse;\n records.push(...data.records);\n\n if (data.cursor) {\n cursor = data.cursor;\n }\n } while (cursor);\n\n return records;\n };\n\n const getPublicationRecords = async (): Promise<PublicationWithUri[]> => {\n try {\n const records = await listRecords(LEXICONS.publication);\n return records.map((record) => ({ ...(record.value as Publication), uri: record.uri }));\n } catch (err) {\n console.error(\"Error fetching publication records:\", err);\n }\n\n return [];\n };\n\n const createRecord = async (\n collection: string,\n value: object\n ): Promise<CreateOrPutRecordResponse> => {\n checkSession();\n\n const response = await fetch(getEndpointUrl(ENDPOINTS.createRecord), {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${accessJwt}`,\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify({\n collection,\n record: value,\n repo: normalizedIdentifier\n })\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create record in ${collection}: ${response.statusText}`);\n }\n\n return (await response.json()) as CreateOrPutRecordResponse;\n };\n\n const getSiteDocumentRecords = async (site: string): Promise<DocumentWithUri[]> => {\n try {\n const records = await listRecords(LEXICONS.document);\n return records\n .filter((record) => (record.value as Document).site === site)\n .map((record) => ({ ...(record.value as Document), uri: record.uri }));\n } catch (err) {\n console.error(\"Error fetching document records:\", err);\n }\n\n return [];\n };\n\n const putRecord = async (\n collection: string,\n recordKey: string,\n value: object\n ): Promise<CreateOrPutRecordResponse> => {\n checkSession();\n\n const response = await fetch(getEndpointUrl(ENDPOINTS.putRecord), {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${accessJwt}`,\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify({\n collection,\n rkey: recordKey,\n record: value,\n repo: normalizedIdentifier\n })\n });\n\n if (!response.ok) {\n throw new Error(`Failed to update record in ${collection}: ${response.statusText}`);\n }\n\n return (await response.json()) as CreateOrPutRecordResponse;\n };\n\n return {\n startSession: async () => {\n const response = await fetch(getEndpointUrl(ENDPOINTS.createSession), {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify({\n identifier: normalizedIdentifier,\n password\n })\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create session: ${response.statusText}`);\n }\n\n const data = (await response.json()) as SessionResponse;\n accessJwt = data.accessJwt;\n },\n\n createOrUpdatePublicationRecord: async (publication: Publication) => {\n checkSession();\n\n // Try getting existing record to determine if we need to create or update\n const existingRecords = await getPublicationRecords();\n const existingRecord = existingRecords.find((record) => record.url === publication.url);\n\n let recordUri: string | undefined;\n if (existingRecord) {\n console.log(`Existing publication record found for URL ${publication.url}, updating...`);\n\n const existingRecordUri = existingRecord.uri;\n const existingRecordKey = extractRecordKey(existingRecordUri);\n\n const updateRecordResponse = await putRecord(\n LEXICONS.publication,\n existingRecordKey,\n publication\n );\n recordUri = updateRecordResponse.uri;\n } else {\n console.log(\n `No existing publication record found for URL ${publication.url}, creating new record...`\n );\n\n const newRecordResponse = await createRecord(LEXICONS.publication, publication);\n recordUri = newRecordResponse.uri;\n }\n\n const recordKey = extractRecordKey(recordUri);\n console.log(\n `Publication record for URL ${publication.url} available at URI: ${recordUri} (record key: ${recordKey})`\n );\n\n return recordUri;\n },\n\n createOrUpdateDocumentRecord: async (document: Document): Promise<string> => {\n checkSession();\n\n // Try getting existing record to determine if we need to create or update\n const existingRecords = await getSiteDocumentRecords(document.site);\n const existingRecord = existingRecords.find((record) => record.path === document.path);\n\n let recordUri: string | undefined;\n if (existingRecord) {\n console.log(`Existing document record found for path ${document.path}, updating...`);\n\n const existingRecordUri = existingRecord.uri;\n const existingRecordKey = extractRecordKey(existingRecordUri);\n\n const updateRecordResponse = await putRecord(\n LEXICONS.document,\n existingRecordKey,\n document\n );\n recordUri = updateRecordResponse.uri;\n } else {\n console.log(\n `No existing document record found for path ${document.path}, creating new record...`\n );\n\n const newRecordResponse = await createRecord(LEXICONS.document, document);\n recordUri = newRecordResponse.uri;\n }\n\n const recordKey = extractRecordKey(recordUri);\n console.log(\n `Document record for path ${document.path} available at URI: ${recordUri} (record key: ${recordKey})`\n );\n\n return recordUri;\n }\n };\n}\n","import { createPublisher } from \"./publisher\";\nimport { LEXICONS, Publication, StandardSitePluginOptions, Document } from \"./types\";\nimport path from \"path\";\nimport fs from \"fs\";\n\nconst DEFAULT_OPTIONS: Partial<StandardSitePluginOptions> = {\n pds: \"https://bsky.social\",\n showInDiscover: true,\n standardSiteDocumentTag: \"standard-site-document\"\n};\n\ntype EleventyAfterEvent = \"eleventy.after\";\n\ninterface EleventyAfterEventData {\n dir: {\n output: string;\n };\n}\n\ninterface EleventyCollectionItemData {\n title: string;\n description?: string;\n bskyPostRef?: string;\n}\n\ninterface EleventyCollectionItem {\n url: string;\n date: Date;\n data: EleventyCollectionItemData;\n}\n\ninterface EleventyCollectionApiLike {\n getFilteredByTag(tag: string): EleventyCollectionItem[];\n}\n\ninterface EleventyConfigLike {\n addCollection(\n name: string,\n callback: (collection: EleventyCollectionApiLike) => EleventyCollectionItem[]\n ): void;\n on(\n event: EleventyAfterEvent,\n callback: (data: EleventyAfterEventData) => Promise<void> | void\n ): void;\n}\n\nexport default function pluginStandardSite(\n eleventyConfig: EleventyConfigLike,\n options: StandardSitePluginOptions\n): void {\n const resolvedOptions: StandardSitePluginOptions = {\n ...DEFAULT_OPTIONS,\n ...options\n };\n\n const documentTag =\n resolvedOptions.standardSiteDocumentTag ?? DEFAULT_OPTIONS.standardSiteDocumentTag!;\n let standardSiteDocumentPosts: EleventyCollectionItem[] = [];\n eleventyConfig.addCollection(\"standardSiteDocuments\", (collection: EleventyCollectionApiLike) => {\n standardSiteDocumentPosts = collection.getFilteredByTag(documentTag);\n return standardSiteDocumentPosts;\n });\n\n eleventyConfig.on(\"eleventy.after\", async ({ dir }) => {\n const publisher = createPublisher(resolvedOptions);\n\n // Authenticating to the PDS\n try {\n await publisher.startSession();\n console.log(\"Successfully authenticated to PDS\");\n } catch (error) {\n console.error(\"Failed to authenticate to PDS:\", error);\n return;\n }\n\n // Get or create the publication record\n const publication: Publication = {\n $type: LEXICONS.publication,\n url: resolvedOptions.publicationUrl,\n name: resolvedOptions.publicationName,\n description: resolvedOptions.publicationDescription,\n preferences: {\n showInDiscover: resolvedOptions.showInDiscover ?? DEFAULT_OPTIONS.showInDiscover!\n }\n };\n const publicationRecordUri = await publisher.createOrUpdatePublicationRecord(publication);\n\n // Expose .well-known endpoint for the publication record\n const outputDir = dir.output;\n const wellKnownEndpointPath = path.join(outputDir, \".well-known\", LEXICONS.publication);\n\n fs.mkdirSync(path.dirname(wellKnownEndpointPath), { recursive: true });\n fs.writeFileSync(wellKnownEndpointPath, publicationRecordUri, \"utf-8\");\n\n // Create or update document records for each tagged post\n for (const post of standardSiteDocumentPosts) {\n console.log(`Processing post: ${post.url}`);\n const documentRecord: Document = {\n site: publicationRecordUri,\n title: post.data.title,\n publishedAt: post.date,\n path: post.url,\n description: post.data.description,\n bskyPostRef: post.data.bskyPostRef\n };\n\n await publisher.createOrUpdateDocumentRecord(documentRecord);\n }\n\n console.log(\n `Finished processing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,MAAM,UAAU,aAAa;GAC7B,QAAQ,IAAI,mCAAmC;EACjD,SAAS,OAAO;GACd,QAAQ,MAAM,kCAAkC,KAAK;GACrD;EACF;EAGA,MAAM,cAA2B;GAC/B,OAAO,SAAS;GAChB,KAAK,gBAAgB;GACrB,MAAM,gBAAgB;GACtB,aAAa,gBAAgB;GAC7B,aAAa,EACX,gBAAgB,gBAAgB,kBAAkB,gBAAgB,eACpE;EACF;EACA,MAAM,uBAAuB,MAAM,UAAU,gCAAgC,WAAW;EAGxF,MAAM,YAAY,IAAI;EACtB,MAAM,wBAAwB,KAAA,QAAK,KAAK,WAAW,eAAe,SAAS,WAAW;EAEtF,GAAA,QAAG,UAAU,KAAA,QAAK,QAAQ,qBAAqB,GAAG,EAAE,WAAW,KAAK,CAAC;EACrE,GAAA,QAAG,cAAc,uBAAuB,sBAAsB,OAAO;EAGrE,KAAK,MAAM,QAAQ,2BAA2B;GAC5C,QAAQ,IAAI,oBAAoB,KAAK,KAAK;GAC1C,MAAM,iBAA2B;IAC/B,MAAM;IACN,OAAO,KAAK,KAAK;IACjB,aAAa,KAAK;IAClB,MAAM,KAAK;IACX,aAAa,KAAK,KAAK;IACvB,aAAa,KAAK,KAAK;GACzB;GAEA,MAAM,UAAU,6BAA6B,cAAc;EAC7D;EAEA,QAAQ,IACN,oEAAoE,0BAA0B,OAAO,YACvG;CACF,CAAC;AACH"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface PublisherOptions {
|
|
3
|
+
pds?: string;
|
|
4
|
+
identifier?: string;
|
|
5
|
+
password?: string;
|
|
6
|
+
}
|
|
7
|
+
type StandardSitePluginOptions = Partial<PublisherOptions> & {
|
|
8
|
+
publicationName: string;
|
|
9
|
+
publicationDescription: string;
|
|
10
|
+
publicationUrl: string;
|
|
11
|
+
standardSiteDocumentTag?: string;
|
|
12
|
+
showInDiscover?: boolean;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/plugin.d.ts
|
|
16
|
+
type EleventyAfterEvent = "eleventy.after";
|
|
17
|
+
interface EleventyAfterEventData {
|
|
18
|
+
dir: {
|
|
19
|
+
output: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
interface EleventyCollectionItemData {
|
|
23
|
+
title: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
bskyPostRef?: string;
|
|
26
|
+
}
|
|
27
|
+
interface EleventyCollectionItem {
|
|
28
|
+
url: string;
|
|
29
|
+
date: Date;
|
|
30
|
+
data: EleventyCollectionItemData;
|
|
31
|
+
}
|
|
32
|
+
interface EleventyCollectionApiLike {
|
|
33
|
+
getFilteredByTag(tag: string): EleventyCollectionItem[];
|
|
34
|
+
}
|
|
35
|
+
interface EleventyConfigLike {
|
|
36
|
+
addCollection(name: string, callback: (collection: EleventyCollectionApiLike) => EleventyCollectionItem[]): void;
|
|
37
|
+
on(event: EleventyAfterEvent, callback: (data: EleventyAfterEventData) => Promise<void> | void): void;
|
|
38
|
+
}
|
|
39
|
+
declare function pluginStandardSite(eleventyConfig: EleventyConfigLike, options: StandardSitePluginOptions): void;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { type StandardSitePluginOptions, pluginStandardSite };
|
|
42
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/plugin.ts"],"mappings":";UAYiB,gBAAA;EACf,GAAA;EACA,UAAA;EACA,QAAA;AAAA;AAAA,KA6DU,yBAAA,GAA4B,OAAO,CAAC,gBAAA;EAC9C,eAAA;EACA,sBAAA;EACA,cAAA;EACA,uBAAA;EACA,cAAA;AAAA;;;KCtEG,kBAAA;AAAA,UAEK,sBAAA;EACR,GAAA;IACE,MAAM;EAAA;AAAA;AAAA,UAIA,0BAAA;EACR,KAAA;EACA,WAAA;EACA,WAAA;AAAA;AAAA,UAGQ,sBAAA;EACR,GAAA;EACA,IAAA,EAAM,IAAA;EACN,IAAA,EAAM,0BAA0B;AAAA;AAAA,UAGxB,yBAAA;EACR,gBAAA,CAAiB,GAAA,WAAc,sBAAsB;AAAA;AAAA,UAG7C,kBAAA;EACR,aAAA,CACE,IAAA,UACA,QAAA,GAAW,UAAA,EAAY,yBAAA,KAA8B,sBAAA;EAEvD,EAAA,CACE,KAAA,EAAO,kBAAA,EACP,QAAA,GAAW,IAAA,EAAM,sBAAA,KAA2B,OAAA;AAAA;AAAA,iBAIxB,kBAAA,CACtB,cAAA,EAAgB,kBAAA,EAChB,OAAA,EAAS,yBAAyB"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface PublisherOptions {
|
|
3
|
+
pds?: string;
|
|
4
|
+
identifier?: string;
|
|
5
|
+
password?: string;
|
|
6
|
+
}
|
|
7
|
+
type StandardSitePluginOptions = Partial<PublisherOptions> & {
|
|
8
|
+
publicationName: string;
|
|
9
|
+
publicationDescription: string;
|
|
10
|
+
publicationUrl: string;
|
|
11
|
+
standardSiteDocumentTag?: string;
|
|
12
|
+
showInDiscover?: boolean;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/plugin.d.ts
|
|
16
|
+
type EleventyAfterEvent = "eleventy.after";
|
|
17
|
+
interface EleventyAfterEventData {
|
|
18
|
+
dir: {
|
|
19
|
+
output: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
interface EleventyCollectionItemData {
|
|
23
|
+
title: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
bskyPostRef?: string;
|
|
26
|
+
}
|
|
27
|
+
interface EleventyCollectionItem {
|
|
28
|
+
url: string;
|
|
29
|
+
date: Date;
|
|
30
|
+
data: EleventyCollectionItemData;
|
|
31
|
+
}
|
|
32
|
+
interface EleventyCollectionApiLike {
|
|
33
|
+
getFilteredByTag(tag: string): EleventyCollectionItem[];
|
|
34
|
+
}
|
|
35
|
+
interface EleventyConfigLike {
|
|
36
|
+
addCollection(name: string, callback: (collection: EleventyCollectionApiLike) => EleventyCollectionItem[]): void;
|
|
37
|
+
on(event: EleventyAfterEvent, callback: (data: EleventyAfterEventData) => Promise<void> | void): void;
|
|
38
|
+
}
|
|
39
|
+
declare function pluginStandardSite(eleventyConfig: EleventyConfigLike, options: StandardSitePluginOptions): void;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { type StandardSitePluginOptions, pluginStandardSite };
|
|
42
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/plugin.ts"],"mappings":";UAYiB,gBAAA;EACf,GAAA;EACA,UAAA;EACA,QAAA;AAAA;AAAA,KA6DU,yBAAA,GAA4B,OAAO,CAAC,gBAAA;EAC9C,eAAA;EACA,sBAAA;EACA,cAAA;EACA,uBAAA;EACA,cAAA;AAAA;;;KCtEG,kBAAA;AAAA,UAEK,sBAAA;EACR,GAAA;IACE,MAAM;EAAA;AAAA;AAAA,UAIA,0BAAA;EACR,KAAA;EACA,WAAA;EACA,WAAA;AAAA;AAAA,UAGQ,sBAAA;EACR,GAAA;EACA,IAAA,EAAM,IAAA;EACN,IAAA,EAAM,0BAA0B;AAAA;AAAA,UAGxB,yBAAA;EACR,gBAAA,CAAiB,GAAA,WAAc,sBAAsB;AAAA;AAAA,UAG7C,kBAAA;EACR,aAAA,CACE,IAAA,UACA,QAAA,GAAW,UAAA,EAAY,yBAAA,KAA8B,sBAAA;EAEvD,EAAA,CACE,KAAA,EAAO,kBAAA,EACP,QAAA,GAAW,IAAA,EAAM,sBAAA,KAA2B,OAAA;AAAA;AAAA,iBAIxB,kBAAA,CACtB,cAAA,EAAgB,kBAAA,EAChB,OAAA,EAAS,yBAAyB"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
//#region src/types.ts
|
|
4
|
+
const ENDPOINTS = {
|
|
5
|
+
createSession: "/xrpc/com.atproto.server.createSession",
|
|
6
|
+
createRecord: "/xrpc/com.atproto.repo.createRecord",
|
|
7
|
+
putRecord: "/xrpc/com.atproto.repo.putRecord",
|
|
8
|
+
listRecords: "/xrpc/com.atproto.repo.listRecords"
|
|
9
|
+
};
|
|
10
|
+
const LEXICONS = {
|
|
11
|
+
publication: "site.standard.publication",
|
|
12
|
+
document: "site.standard.document"
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/utils.ts
|
|
16
|
+
function extractRecordKey(uri) {
|
|
17
|
+
const parts = uri.split("/");
|
|
18
|
+
return parts[parts.length - 1];
|
|
19
|
+
}
|
|
20
|
+
function normalizePdsUrl(url) {
|
|
21
|
+
let normalizedUrl = url.trim();
|
|
22
|
+
if (normalizedUrl.endsWith("/")) normalizedUrl = normalizedUrl.slice(0, -1);
|
|
23
|
+
if (normalizedUrl.length === 0) throw new Error("PDS URL cannot be empty after normalization.");
|
|
24
|
+
if (!normalizedUrl.startsWith("http://") && !normalizedUrl.startsWith("https://")) normalizedUrl = `https://${normalizedUrl}`;
|
|
25
|
+
return normalizedUrl;
|
|
26
|
+
}
|
|
27
|
+
function normalizeIdentifier(identifier) {
|
|
28
|
+
let normalizedIdentifier = identifier.trim();
|
|
29
|
+
if (normalizedIdentifier.startsWith("@")) normalizedIdentifier = normalizedIdentifier.slice(1);
|
|
30
|
+
if (normalizedIdentifier.length === 0) throw new Error("Identifier cannot be empty after normalization.");
|
|
31
|
+
return normalizedIdentifier;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/publisher.ts
|
|
35
|
+
function createPublisher({ pds, identifier, password }) {
|
|
36
|
+
if (!pds || !identifier || !password) throw new Error("Missing required PDS configuration: pds, identifier, and password are all required.");
|
|
37
|
+
const normalizedPds = normalizePdsUrl(pds);
|
|
38
|
+
const normalizedIdentifier = normalizeIdentifier(identifier);
|
|
39
|
+
const getEndpointUrl = (endpoint) => `${normalizedPds}${endpoint}`;
|
|
40
|
+
let accessJwt = null;
|
|
41
|
+
const checkSession = () => {
|
|
42
|
+
if (!accessJwt) throw new Error("Session not started. Call startSession() before making requests.");
|
|
43
|
+
};
|
|
44
|
+
const listRecords = async (collection) => {
|
|
45
|
+
const baseEndpointUrl = getEndpointUrl(ENDPOINTS.listRecords);
|
|
46
|
+
let cursor;
|
|
47
|
+
const records = [];
|
|
48
|
+
do {
|
|
49
|
+
const params = new URLSearchParams();
|
|
50
|
+
params.set("collection", collection);
|
|
51
|
+
params.set("repo", normalizedIdentifier);
|
|
52
|
+
if (cursor) params.set("cursor", cursor);
|
|
53
|
+
const url = new URL(baseEndpointUrl);
|
|
54
|
+
url.search = params.toString();
|
|
55
|
+
const response = await fetch(url.toString(), {
|
|
56
|
+
method: "GET",
|
|
57
|
+
headers: { "Content-Type": "application/json" }
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok) throw new Error(`Failed to list ${collection} records: ${response.statusText}`);
|
|
60
|
+
const data = await response.json();
|
|
61
|
+
records.push(...data.records);
|
|
62
|
+
if (data.cursor) cursor = data.cursor;
|
|
63
|
+
} while (cursor);
|
|
64
|
+
return records;
|
|
65
|
+
};
|
|
66
|
+
const getPublicationRecords = async () => {
|
|
67
|
+
try {
|
|
68
|
+
return (await listRecords(LEXICONS.publication)).map((record) => ({
|
|
69
|
+
...record.value,
|
|
70
|
+
uri: record.uri
|
|
71
|
+
}));
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.error("Error fetching publication records:", err);
|
|
74
|
+
}
|
|
75
|
+
return [];
|
|
76
|
+
};
|
|
77
|
+
const createRecord = async (collection, value) => {
|
|
78
|
+
checkSession();
|
|
79
|
+
const response = await fetch(getEndpointUrl(ENDPOINTS.createRecord), {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: {
|
|
82
|
+
Authorization: `Bearer ${accessJwt}`,
|
|
83
|
+
"Content-Type": "application/json"
|
|
84
|
+
},
|
|
85
|
+
body: JSON.stringify({
|
|
86
|
+
collection,
|
|
87
|
+
record: value,
|
|
88
|
+
repo: normalizedIdentifier
|
|
89
|
+
})
|
|
90
|
+
});
|
|
91
|
+
if (!response.ok) throw new Error(`Failed to create record in ${collection}: ${response.statusText}`);
|
|
92
|
+
return await response.json();
|
|
93
|
+
};
|
|
94
|
+
const getSiteDocumentRecords = async (site) => {
|
|
95
|
+
try {
|
|
96
|
+
return (await listRecords(LEXICONS.document)).filter((record) => record.value.site === site).map((record) => ({
|
|
97
|
+
...record.value,
|
|
98
|
+
uri: record.uri
|
|
99
|
+
}));
|
|
100
|
+
} catch (err) {
|
|
101
|
+
console.error("Error fetching document records:", err);
|
|
102
|
+
}
|
|
103
|
+
return [];
|
|
104
|
+
};
|
|
105
|
+
const putRecord = async (collection, recordKey, value) => {
|
|
106
|
+
checkSession();
|
|
107
|
+
const response = await fetch(getEndpointUrl(ENDPOINTS.putRecord), {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: {
|
|
110
|
+
Authorization: `Bearer ${accessJwt}`,
|
|
111
|
+
"Content-Type": "application/json"
|
|
112
|
+
},
|
|
113
|
+
body: JSON.stringify({
|
|
114
|
+
collection,
|
|
115
|
+
rkey: recordKey,
|
|
116
|
+
record: value,
|
|
117
|
+
repo: normalizedIdentifier
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
if (!response.ok) throw new Error(`Failed to update record in ${collection}: ${response.statusText}`);
|
|
121
|
+
return await response.json();
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
startSession: async () => {
|
|
125
|
+
const response = await fetch(getEndpointUrl(ENDPOINTS.createSession), {
|
|
126
|
+
method: "POST",
|
|
127
|
+
headers: { "Content-Type": "application/json" },
|
|
128
|
+
body: JSON.stringify({
|
|
129
|
+
identifier: normalizedIdentifier,
|
|
130
|
+
password
|
|
131
|
+
})
|
|
132
|
+
});
|
|
133
|
+
if (!response.ok) throw new Error(`Failed to create session: ${response.statusText}`);
|
|
134
|
+
accessJwt = (await response.json()).accessJwt;
|
|
135
|
+
},
|
|
136
|
+
createOrUpdatePublicationRecord: async (publication) => {
|
|
137
|
+
checkSession();
|
|
138
|
+
const existingRecord = (await getPublicationRecords()).find((record) => record.url === publication.url);
|
|
139
|
+
let recordUri;
|
|
140
|
+
if (existingRecord) {
|
|
141
|
+
console.log(`Existing publication record found for URL ${publication.url}, updating...`);
|
|
142
|
+
const existingRecordUri = existingRecord.uri;
|
|
143
|
+
const existingRecordKey = extractRecordKey(existingRecordUri);
|
|
144
|
+
recordUri = (await putRecord(LEXICONS.publication, existingRecordKey, publication)).uri;
|
|
145
|
+
} else {
|
|
146
|
+
console.log(`No existing publication record found for URL ${publication.url}, creating new record...`);
|
|
147
|
+
recordUri = (await createRecord(LEXICONS.publication, publication)).uri;
|
|
148
|
+
}
|
|
149
|
+
const recordKey = extractRecordKey(recordUri);
|
|
150
|
+
console.log(`Publication record for URL ${publication.url} available at URI: ${recordUri} (record key: ${recordKey})`);
|
|
151
|
+
return recordUri;
|
|
152
|
+
},
|
|
153
|
+
createOrUpdateDocumentRecord: async (document) => {
|
|
154
|
+
checkSession();
|
|
155
|
+
const existingRecord = (await getSiteDocumentRecords(document.site)).find((record) => record.path === document.path);
|
|
156
|
+
let recordUri;
|
|
157
|
+
if (existingRecord) {
|
|
158
|
+
console.log(`Existing document record found for path ${document.path}, updating...`);
|
|
159
|
+
const existingRecordUri = existingRecord.uri;
|
|
160
|
+
const existingRecordKey = extractRecordKey(existingRecordUri);
|
|
161
|
+
recordUri = (await putRecord(LEXICONS.document, existingRecordKey, document)).uri;
|
|
162
|
+
} else {
|
|
163
|
+
console.log(`No existing document record found for path ${document.path}, creating new record...`);
|
|
164
|
+
recordUri = (await createRecord(LEXICONS.document, document)).uri;
|
|
165
|
+
}
|
|
166
|
+
const recordKey = extractRecordKey(recordUri);
|
|
167
|
+
console.log(`Document record for path ${document.path} available at URI: ${recordUri} (record key: ${recordKey})`);
|
|
168
|
+
return recordUri;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/plugin.ts
|
|
174
|
+
const DEFAULT_OPTIONS = {
|
|
175
|
+
pds: "https://bsky.social",
|
|
176
|
+
showInDiscover: true,
|
|
177
|
+
standardSiteDocumentTag: "standard-site-document"
|
|
178
|
+
};
|
|
179
|
+
function pluginStandardSite(eleventyConfig, options) {
|
|
180
|
+
const resolvedOptions = {
|
|
181
|
+
...DEFAULT_OPTIONS,
|
|
182
|
+
...options
|
|
183
|
+
};
|
|
184
|
+
const documentTag = resolvedOptions.standardSiteDocumentTag ?? DEFAULT_OPTIONS.standardSiteDocumentTag;
|
|
185
|
+
let standardSiteDocumentPosts = [];
|
|
186
|
+
eleventyConfig.addCollection("standardSiteDocuments", (collection) => {
|
|
187
|
+
standardSiteDocumentPosts = collection.getFilteredByTag(documentTag);
|
|
188
|
+
return standardSiteDocumentPosts;
|
|
189
|
+
});
|
|
190
|
+
eleventyConfig.on("eleventy.after", async ({ dir }) => {
|
|
191
|
+
const publisher = createPublisher(resolvedOptions);
|
|
192
|
+
try {
|
|
193
|
+
await publisher.startSession();
|
|
194
|
+
console.log("Successfully authenticated to PDS");
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.error("Failed to authenticate to PDS:", error);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const publication = {
|
|
200
|
+
$type: LEXICONS.publication,
|
|
201
|
+
url: resolvedOptions.publicationUrl,
|
|
202
|
+
name: resolvedOptions.publicationName,
|
|
203
|
+
description: resolvedOptions.publicationDescription,
|
|
204
|
+
preferences: { showInDiscover: resolvedOptions.showInDiscover ?? DEFAULT_OPTIONS.showInDiscover }
|
|
205
|
+
};
|
|
206
|
+
const publicationRecordUri = await publisher.createOrUpdatePublicationRecord(publication);
|
|
207
|
+
const outputDir = dir.output;
|
|
208
|
+
const wellKnownEndpointPath = path.join(outputDir, ".well-known", LEXICONS.publication);
|
|
209
|
+
fs.mkdirSync(path.dirname(wellKnownEndpointPath), { recursive: true });
|
|
210
|
+
fs.writeFileSync(wellKnownEndpointPath, publicationRecordUri, "utf-8");
|
|
211
|
+
for (const post of standardSiteDocumentPosts) {
|
|
212
|
+
console.log(`Processing post: ${post.url}`);
|
|
213
|
+
const documentRecord = {
|
|
214
|
+
site: publicationRecordUri,
|
|
215
|
+
title: post.data.title,
|
|
216
|
+
publishedAt: post.date,
|
|
217
|
+
path: post.url,
|
|
218
|
+
description: post.data.description,
|
|
219
|
+
bskyPostRef: post.data.bskyPostRef
|
|
220
|
+
};
|
|
221
|
+
await publisher.createOrUpdateDocumentRecord(documentRecord);
|
|
222
|
+
}
|
|
223
|
+
console.log(`Finished processing Standard.Site records with 1 publication and ${standardSiteDocumentPosts.length} documents.`);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
227
|
+
export { pluginStandardSite };
|
|
228
|
+
|
|
229
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/types.ts","../src/utils.ts","../src/publisher.ts","../src/plugin.ts"],"sourcesContent":["export const ENDPOINTS = {\n createSession: \"/xrpc/com.atproto.server.createSession\",\n createRecord: \"/xrpc/com.atproto.repo.createRecord\",\n putRecord: \"/xrpc/com.atproto.repo.putRecord\",\n listRecords: \"/xrpc/com.atproto.repo.listRecords\"\n};\n\nexport const LEXICONS = {\n publication: \"site.standard.publication\",\n document: \"site.standard.document\"\n};\n\nexport interface PublisherOptions {\n pds?: string;\n identifier?: string;\n password?: string;\n}\n\nexport interface SessionResponse {\n accessJwt: string;\n}\n\nexport interface Record {\n cid: string;\n uri: string;\n value: object;\n}\n\nexport interface CreateOrPutRecordResponse {\n uri: string;\n cid: string;\n commit: {\n cid: string;\n rev: string;\n };\n validationStatus: string;\n}\n\nexport interface ListRecordsResponse {\n cursor: string | null;\n records: Record[];\n}\n\nexport interface Publication {\n $type: string;\n url: string;\n name: string;\n description: string;\n preferences: {\n showInDiscover: boolean;\n };\n}\n\nexport interface Document {\n site: string;\n title: string;\n publishedAt: Date;\n path?: string;\n description?: string;\n bskyPostRef?: string;\n}\n\nexport interface PublicationWithUri extends Publication {\n uri: string;\n}\n\nexport interface DocumentWithUri extends Document {\n uri: string;\n}\n\nexport interface Publisher {\n startSession: () => Promise<void>;\n createOrUpdatePublicationRecord: (publication: Publication) => Promise<string>;\n createOrUpdateDocumentRecord: (document: Document) => Promise<string>;\n}\n\nexport type StandardSitePluginOptions = Partial<PublisherOptions> & {\n publicationName: string;\n publicationDescription: string;\n publicationUrl: string;\n standardSiteDocumentTag?: string;\n showInDiscover?: boolean;\n};\n","export function extractRecordKey(uri: string): string {\n const parts = uri.split(\"/\");\n return parts[parts.length - 1];\n}\n\nexport function normalizePdsUrl(url: string): string {\n let normalizedUrl = url.trim();\n\n if (normalizedUrl.endsWith(\"/\")) {\n normalizedUrl = normalizedUrl.slice(0, -1);\n }\n\n if (normalizedUrl.length === 0) {\n throw new Error(\"PDS URL cannot be empty after normalization.\");\n }\n\n if (!normalizedUrl.startsWith(\"http://\") && !normalizedUrl.startsWith(\"https://\")) {\n normalizedUrl = `https://${normalizedUrl}`;\n }\n\n return normalizedUrl;\n}\n\nexport function normalizeIdentifier(identifier: string): string {\n let normalizedIdentifier = identifier.trim();\n\n if (normalizedIdentifier.startsWith(\"@\")) {\n normalizedIdentifier = normalizedIdentifier.slice(1);\n }\n\n if (normalizedIdentifier.length === 0) {\n throw new Error(\"Identifier cannot be empty after normalization.\");\n }\n\n return normalizedIdentifier;\n}\n","import {\n ENDPOINTS,\n LEXICONS,\n PublisherOptions,\n SessionResponse,\n Record,\n CreateOrPutRecordResponse,\n ListRecordsResponse,\n Publication,\n PublicationWithUri,\n Publisher,\n Document,\n DocumentWithUri\n} from \"./types\";\nimport { extractRecordKey, normalizePdsUrl, normalizeIdentifier } from \"./utils\";\n\nexport function createPublisher({ pds, identifier, password }: PublisherOptions): Publisher {\n if (!pds || !identifier || !password) {\n throw new Error(\n \"Missing required PDS configuration: pds, identifier, and password are all required.\"\n );\n }\n\n const normalizedPds = normalizePdsUrl(pds);\n const normalizedIdentifier = normalizeIdentifier(identifier);\n const getEndpointUrl = (endpoint: string) => `${normalizedPds}${endpoint}`;\n\n let accessJwt: string | null = null;\n const checkSession = () => {\n if (!accessJwt) {\n throw new Error(\"Session not started. Call startSession() before making requests.\");\n }\n };\n\n const listRecords = async (collection: string): Promise<Record[]> => {\n const baseEndpointUrl = getEndpointUrl(ENDPOINTS.listRecords);\n\n let cursor: string | undefined;\n const records: Record[] = [];\n do {\n const params = new URLSearchParams();\n params.set(\"collection\", collection);\n params.set(\"repo\", normalizedIdentifier);\n if (cursor) {\n params.set(\"cursor\", cursor);\n }\n\n const url = new URL(baseEndpointUrl);\n url.search = params.toString();\n\n const response = await fetch(url.toString(), {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\"\n }\n });\n\n if (!response.ok) {\n throw new Error(`Failed to list ${collection} records: ${response.statusText}`);\n }\n\n const data = (await response.json()) as ListRecordsResponse;\n records.push(...data.records);\n\n if (data.cursor) {\n cursor = data.cursor;\n }\n } while (cursor);\n\n return records;\n };\n\n const getPublicationRecords = async (): Promise<PublicationWithUri[]> => {\n try {\n const records = await listRecords(LEXICONS.publication);\n return records.map((record) => ({ ...(record.value as Publication), uri: record.uri }));\n } catch (err) {\n console.error(\"Error fetching publication records:\", err);\n }\n\n return [];\n };\n\n const createRecord = async (\n collection: string,\n value: object\n ): Promise<CreateOrPutRecordResponse> => {\n checkSession();\n\n const response = await fetch(getEndpointUrl(ENDPOINTS.createRecord), {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${accessJwt}`,\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify({\n collection,\n record: value,\n repo: normalizedIdentifier\n })\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create record in ${collection}: ${response.statusText}`);\n }\n\n return (await response.json()) as CreateOrPutRecordResponse;\n };\n\n const getSiteDocumentRecords = async (site: string): Promise<DocumentWithUri[]> => {\n try {\n const records = await listRecords(LEXICONS.document);\n return records\n .filter((record) => (record.value as Document).site === site)\n .map((record) => ({ ...(record.value as Document), uri: record.uri }));\n } catch (err) {\n console.error(\"Error fetching document records:\", err);\n }\n\n return [];\n };\n\n const putRecord = async (\n collection: string,\n recordKey: string,\n value: object\n ): Promise<CreateOrPutRecordResponse> => {\n checkSession();\n\n const response = await fetch(getEndpointUrl(ENDPOINTS.putRecord), {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${accessJwt}`,\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify({\n collection,\n rkey: recordKey,\n record: value,\n repo: normalizedIdentifier\n })\n });\n\n if (!response.ok) {\n throw new Error(`Failed to update record in ${collection}: ${response.statusText}`);\n }\n\n return (await response.json()) as CreateOrPutRecordResponse;\n };\n\n return {\n startSession: async () => {\n const response = await fetch(getEndpointUrl(ENDPOINTS.createSession), {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify({\n identifier: normalizedIdentifier,\n password\n })\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create session: ${response.statusText}`);\n }\n\n const data = (await response.json()) as SessionResponse;\n accessJwt = data.accessJwt;\n },\n\n createOrUpdatePublicationRecord: async (publication: Publication) => {\n checkSession();\n\n // Try getting existing record to determine if we need to create or update\n const existingRecords = await getPublicationRecords();\n const existingRecord = existingRecords.find((record) => record.url === publication.url);\n\n let recordUri: string | undefined;\n if (existingRecord) {\n console.log(`Existing publication record found for URL ${publication.url}, updating...`);\n\n const existingRecordUri = existingRecord.uri;\n const existingRecordKey = extractRecordKey(existingRecordUri);\n\n const updateRecordResponse = await putRecord(\n LEXICONS.publication,\n existingRecordKey,\n publication\n );\n recordUri = updateRecordResponse.uri;\n } else {\n console.log(\n `No existing publication record found for URL ${publication.url}, creating new record...`\n );\n\n const newRecordResponse = await createRecord(LEXICONS.publication, publication);\n recordUri = newRecordResponse.uri;\n }\n\n const recordKey = extractRecordKey(recordUri);\n console.log(\n `Publication record for URL ${publication.url} available at URI: ${recordUri} (record key: ${recordKey})`\n );\n\n return recordUri;\n },\n\n createOrUpdateDocumentRecord: async (document: Document): Promise<string> => {\n checkSession();\n\n // Try getting existing record to determine if we need to create or update\n const existingRecords = await getSiteDocumentRecords(document.site);\n const existingRecord = existingRecords.find((record) => record.path === document.path);\n\n let recordUri: string | undefined;\n if (existingRecord) {\n console.log(`Existing document record found for path ${document.path}, updating...`);\n\n const existingRecordUri = existingRecord.uri;\n const existingRecordKey = extractRecordKey(existingRecordUri);\n\n const updateRecordResponse = await putRecord(\n LEXICONS.document,\n existingRecordKey,\n document\n );\n recordUri = updateRecordResponse.uri;\n } else {\n console.log(\n `No existing document record found for path ${document.path}, creating new record...`\n );\n\n const newRecordResponse = await createRecord(LEXICONS.document, document);\n recordUri = newRecordResponse.uri;\n }\n\n const recordKey = extractRecordKey(recordUri);\n console.log(\n `Document record for path ${document.path} available at URI: ${recordUri} (record key: ${recordKey})`\n );\n\n return recordUri;\n }\n };\n}\n","import { createPublisher } from \"./publisher\";\nimport { LEXICONS, Publication, StandardSitePluginOptions, Document } from \"./types\";\nimport path from \"path\";\nimport fs from \"fs\";\n\nconst DEFAULT_OPTIONS: Partial<StandardSitePluginOptions> = {\n pds: \"https://bsky.social\",\n showInDiscover: true,\n standardSiteDocumentTag: \"standard-site-document\"\n};\n\ntype EleventyAfterEvent = \"eleventy.after\";\n\ninterface EleventyAfterEventData {\n dir: {\n output: string;\n };\n}\n\ninterface EleventyCollectionItemData {\n title: string;\n description?: string;\n bskyPostRef?: string;\n}\n\ninterface EleventyCollectionItem {\n url: string;\n date: Date;\n data: EleventyCollectionItemData;\n}\n\ninterface EleventyCollectionApiLike {\n getFilteredByTag(tag: string): EleventyCollectionItem[];\n}\n\ninterface EleventyConfigLike {\n addCollection(\n name: string,\n callback: (collection: EleventyCollectionApiLike) => EleventyCollectionItem[]\n ): void;\n on(\n event: EleventyAfterEvent,\n callback: (data: EleventyAfterEventData) => Promise<void> | void\n ): void;\n}\n\nexport default function pluginStandardSite(\n eleventyConfig: EleventyConfigLike,\n options: StandardSitePluginOptions\n): void {\n const resolvedOptions: StandardSitePluginOptions = {\n ...DEFAULT_OPTIONS,\n ...options\n };\n\n const documentTag =\n resolvedOptions.standardSiteDocumentTag ?? DEFAULT_OPTIONS.standardSiteDocumentTag!;\n let standardSiteDocumentPosts: EleventyCollectionItem[] = [];\n eleventyConfig.addCollection(\"standardSiteDocuments\", (collection: EleventyCollectionApiLike) => {\n standardSiteDocumentPosts = collection.getFilteredByTag(documentTag);\n return standardSiteDocumentPosts;\n });\n\n eleventyConfig.on(\"eleventy.after\", async ({ dir }) => {\n const publisher = createPublisher(resolvedOptions);\n\n // Authenticating to the PDS\n try {\n await publisher.startSession();\n console.log(\"Successfully authenticated to PDS\");\n } catch (error) {\n console.error(\"Failed to authenticate to PDS:\", error);\n return;\n }\n\n // Get or create the publication record\n const publication: Publication = {\n $type: LEXICONS.publication,\n url: resolvedOptions.publicationUrl,\n name: resolvedOptions.publicationName,\n description: resolvedOptions.publicationDescription,\n preferences: {\n showInDiscover: resolvedOptions.showInDiscover ?? DEFAULT_OPTIONS.showInDiscover!\n }\n };\n const publicationRecordUri = await publisher.createOrUpdatePublicationRecord(publication);\n\n // Expose .well-known endpoint for the publication record\n const outputDir = dir.output;\n const wellKnownEndpointPath = path.join(outputDir, \".well-known\", LEXICONS.publication);\n\n fs.mkdirSync(path.dirname(wellKnownEndpointPath), { recursive: true });\n fs.writeFileSync(wellKnownEndpointPath, publicationRecordUri, \"utf-8\");\n\n // Create or update document records for each tagged post\n for (const post of standardSiteDocumentPosts) {\n console.log(`Processing post: ${post.url}`);\n const documentRecord: Document = {\n site: publicationRecordUri,\n title: post.data.title,\n publishedAt: post.date,\n path: post.url,\n description: post.data.description,\n bskyPostRef: post.data.bskyPostRef\n };\n\n await publisher.createOrUpdateDocumentRecord(documentRecord);\n }\n\n console.log(\n `Finished processing Standard.Site records with 1 publication and ${standardSiteDocumentPosts.length} documents.`\n );\n });\n}\n"],"mappings":";;;AAAA,MAAa,YAAY;CACvB,eAAe;CACf,cAAc;CACd,WAAW;CACX,aAAa;AACf;AAEA,MAAa,WAAW;CACtB,aAAa;CACb,UAAU;AACZ;;;ACVA,SAAgB,iBAAiB,KAAqB;CACpD,MAAM,QAAQ,IAAI,MAAM,GAAG;CAC3B,OAAO,MAAM,MAAM,SAAS;AAC9B;AAEA,SAAgB,gBAAgB,KAAqB;CACnD,IAAI,gBAAgB,IAAI,KAAK;CAE7B,IAAI,cAAc,SAAS,GAAG,GAC5B,gBAAgB,cAAc,MAAM,GAAG,EAAE;CAG3C,IAAI,cAAc,WAAW,GAC3B,MAAM,IAAI,MAAM,8CAA8C;CAGhE,IAAI,CAAC,cAAc,WAAW,SAAS,KAAK,CAAC,cAAc,WAAW,UAAU,GAC9E,gBAAgB,WAAW;CAG7B,OAAO;AACT;AAEA,SAAgB,oBAAoB,YAA4B;CAC9D,IAAI,uBAAuB,WAAW,KAAK;CAE3C,IAAI,qBAAqB,WAAW,GAAG,GACrC,uBAAuB,qBAAqB,MAAM,CAAC;CAGrD,IAAI,qBAAqB,WAAW,GAClC,MAAM,IAAI,MAAM,iDAAiD;CAGnE,OAAO;AACT;;;ACnBA,SAAgB,gBAAgB,EAAE,KAAK,YAAY,YAAyC;CAC1F,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,UAC1B,MAAM,IAAI,MACR,qFACF;CAGF,MAAM,gBAAgB,gBAAgB,GAAG;CACzC,MAAM,uBAAuB,oBAAoB,UAAU;CAC3D,MAAM,kBAAkB,aAAqB,GAAG,gBAAgB;CAEhE,IAAI,YAA2B;CAC/B,MAAM,qBAAqB;EACzB,IAAI,CAAC,WACH,MAAM,IAAI,MAAM,kEAAkE;CAEtF;CAEA,MAAM,cAAc,OAAO,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rD,MAAM,YAAY,gBAAgB,eAAe;EAGjD,IAAI;GACF,MAAM,UAAU,aAAa;GAC7B,QAAQ,IAAI,mCAAmC;EACjD,SAAS,OAAO;GACd,QAAQ,MAAM,kCAAkC,KAAK;GACrD;EACF;EAGA,MAAM,cAA2B;GAC/B,OAAO,SAAS;GAChB,KAAK,gBAAgB;GACrB,MAAM,gBAAgB;GACtB,aAAa,gBAAgB;GAC7B,aAAa,EACX,gBAAgB,gBAAgB,kBAAkB,gBAAgB,eACpE;EACF;EACA,MAAM,uBAAuB,MAAM,UAAU,gCAAgC,WAAW;EAGxF,MAAM,YAAY,IAAI;EACtB,MAAM,wBAAwB,KAAK,KAAK,WAAW,eAAe,SAAS,WAAW;EAEtF,GAAG,UAAU,KAAK,QAAQ,qBAAqB,GAAG,EAAE,WAAW,KAAK,CAAC;EACrE,GAAG,cAAc,uBAAuB,sBAAsB,OAAO;EAGrE,KAAK,MAAM,QAAQ,2BAA2B;GAC5C,QAAQ,IAAI,oBAAoB,KAAK,KAAK;GAC1C,MAAM,iBAA2B;IAC/B,MAAM;IACN,OAAO,KAAK,KAAK;IACjB,aAAa,KAAK;IAClB,MAAM,KAAK;IACX,aAAa,KAAK,KAAK;IACvB,aAAa,KAAK,KAAK;GACzB;GAEA,MAAM,UAAU,6BAA6B,cAAc;EAC7D;EAEA,QAAQ,IACN,oEAAoE,0BAA0B,OAAO,YACvG;CACF,CAAC;AACH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eleventy-plugin-standard-site",
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
|
+
"description": "11ty plugin to generate and publish Standard.Site records on your AT Protocol PDS for your site.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"11ty",
|
|
7
|
+
"11ty-plugin",
|
|
8
|
+
"eleventy",
|
|
9
|
+
"eleventy-plugin",
|
|
10
|
+
"standard.site",
|
|
11
|
+
"atproto",
|
|
12
|
+
"lexicon",
|
|
13
|
+
"atprotocol",
|
|
14
|
+
"pds"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/aitorres/eleventy-plugin-standard-site#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/aitorres/eleventy-plugin-standard-site/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/aitorres/eleventy-plugin-standard-site.git"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": {
|
|
26
|
+
"name": "Andrés Ignacio Torres",
|
|
27
|
+
"email": "dev@aitorres.com",
|
|
28
|
+
"url": "https://aitorres.com"
|
|
29
|
+
},
|
|
30
|
+
"type": "module",
|
|
31
|
+
"main": "./dist/index.cjs",
|
|
32
|
+
"module": "./dist/index.mjs",
|
|
33
|
+
"types": "./dist/index.d.mts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.mts",
|
|
37
|
+
"import": "./dist/index.mjs",
|
|
38
|
+
"require": "./dist/index.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"README.md",
|
|
44
|
+
"LICENSE"
|
|
45
|
+
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"clean": "rimraf dist",
|
|
48
|
+
"build": "tsdown",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"lint": "eslint .",
|
|
51
|
+
"format": "prettier --write .",
|
|
52
|
+
"format:check": "prettier --check .",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"test:watch": "vitest"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@eslint/js": "^10.0.1",
|
|
58
|
+
"@types/node": "^25.9.3",
|
|
59
|
+
"eslint": "^10.5.0",
|
|
60
|
+
"globals": "^17.6.0",
|
|
61
|
+
"prettier": "^3.8.4",
|
|
62
|
+
"rimraf": "^6.1.3",
|
|
63
|
+
"tsdown": "^0.22.2",
|
|
64
|
+
"typescript": "^6.0.3",
|
|
65
|
+
"typescript-eslint": "^8.61.0",
|
|
66
|
+
"vitest": "^4.1.8"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=18"
|
|
70
|
+
},
|
|
71
|
+
"prettier": {
|
|
72
|
+
"semi": true,
|
|
73
|
+
"singleQuote": false,
|
|
74
|
+
"trailingComma": "none",
|
|
75
|
+
"printWidth": 100,
|
|
76
|
+
"tabWidth": 2,
|
|
77
|
+
"useTabs": false
|
|
78
|
+
}
|
|
79
|
+
}
|