-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
186 lines (172 loc) · 10.7 KB
/
Copy path.eleventy.js
File metadata and controls
186 lines (172 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const markdownItTaskLists = require("markdown-it-task-lists");
const pluginSitemap = require("@quasibit/eleventy-plugin-sitemap");
const fs = require("fs");
const crypto = require("crypto");
const path = require("path");
module.exports = function (eleventyConfig) {
// ── Plugins ──────────────────────────────────────────────────────────────
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(pluginSitemap, {
sitemap: {
hostname: "https://www.postgis-python.com",
},
});
// ── Markdown config ───────────────────────────────────────────────────────
const md = markdownIt({ html: true, linkify: true, typographer: true })
.use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.headerLink({ safariReaderFix: true }),
slugify: (s) =>
s.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-"),
})
.use(markdownItTaskLists, { enabled: true, label: true, labelAfter: true });
eleventyConfig.setLibrary("md", md);
// ── Passthrough copies ────────────────────────────────────────────────────
eleventyConfig.addPassthroughCopy("assets");
eleventyConfig.addPassthroughCopy({ "assets/icons/favicon.ico": "favicon.ico" });
eleventyConfig.addPassthroughCopy({ "assets/manifest.json": "manifest.json" });
eleventyConfig.addPassthroughCopy({ "assets/sw.js": "sw.js" });
eleventyConfig.addPassthroughCopy("_headers");
// ── Filters ───────────────────────────────────────────────────────────────
// Build breadcrumb data from a page URL
eleventyConfig.addFilter("breadcrumbs", function (url) {
const labels = {
"advanced-gist-indexing-optimization": "Advanced GiST Indexing",
"mastering-core-spatial-query-patterns": "Core Spatial Queries",
"sqlalchemy-and-geoalchemy-integration-workflows": "SQLAlchemy & GeoAlchemy",
"partial-gist-indexes": "Partial GiST Indexes",
"composite-spatial-indexes": "Composite Spatial Indexes",
"index-only-scan-strategies": "Index-Only Scan Strategies",
"query-plan-analysis-with-explain": "Query Plan Analysis",
"bounding-box-filtering": "Bounding Box Filtering",
"knn-nearest-neighbor-queries": "KNN Nearest Neighbor",
"spatial-joins": "Spatial Joins",
"st_dwithin-radius-searches": "ST_DWithin Radius Searches",
"model-mapping-with-geoalchemy2": "Model Mapping with GeoAlchemy2",
"session-management-for-spatial-data": "Session Management",
"hybrid-properties-for-geometry": "Hybrid Properties",
"type-coercion-and-serialization": "Type Coercion & Serialization",
"creating-partial-indexes-for-active-map-regions": "Creating Partial Indexes for Active Map Regions",
"composite-indexes-for-geometry-and-timestamp-columns": "Composite Indexes for Geometry & Timestamp Columns",
"leveraging-index-only-scans-for-point-data": "Leveraging Index-Only Scans for Point Data",
"reading-explain-analyze-output-for-spatial-joins": "Reading EXPLAIN ANALYZE Output for Spatial Joins",
"optimizing-bounding-box-queries-with-operator": "Optimizing Bounding Box Queries with && Operator",
"implementing-knn-search-with-operator": "Implementing KNN Search with <-> Operator",
"batch-processing-spatial-joins-in-python": "Batch Processing Spatial Joins in Python",
"tuning-st_dwithin-for-high-traffic-apis": "Tuning ST_DWithin for High-Traffic APIs",
"configuring-geoalchemy2-geometry-columns-in-fastapi": "Configuring GeoAlchemy2 Geometry Columns in FastAPI",
"handling-session-timeouts-during-bulk-spatial-inserts": "Handling Session Timeouts During Bulk Spatial Inserts",
// ── Additional top-level section labels ──
"spatial-schema-migrations-and-evolution": "Spatial Schema Migrations",
"spatial-performance-monitoring-and-observability": "Performance Monitoring",
tools: "Tools",
// ── Additional section labels ──
"adding-geometry-columns-to-live-tables": "Adding Geometry Columns to Live Tables",
"in-place-srid-reprojection": "In-Place SRID Reprojection",
"concurrent-index-builds": "Concurrent Index Builds",
"backfilling-and-zero-downtime-migrations": "Backfilling & Zero-Downtime Migrations",
"pg-stat-statements-for-spatial-workloads": "pg_stat_statements for Spatial Workloads",
"detecting-gist-index-bloat": "Detecting GiST Index Bloat",
"autovacuum-tuning-for-geometry-tables": "Autovacuum Tuning for Geometry Tables",
"choosing-a-spatial-index-type": "Choosing a Spatial Index Type",
"choosing-a-postgis-driver": "Choosing a PostGIS Driver",
// ── Additional deep-dive page labels ──
"alter-table-add-geometry-column-without-locking": "ALTER TABLE ADD COLUMN Geometry Without Locking",
"batch-st_transform-reprojection-in-python": "Batch ST_Transform Reprojection in Python",
"create-index-concurrently-on-large-spatial-tables": "CREATE INDEX CONCURRENTLY on Large Spatial Tables",
"backfilling-geometry-from-latitude-longitude-columns": "Backfilling Geometry From Latitude/Longitude Columns",
"finding-slow-st-function-calls-with-pg-stat-statements": "Finding Slow ST_ Function Calls with pg_stat_statements",
"measuring-gist-index-bloat-with-pgstattuple": "Measuring GiST Index Bloat with pgstattuple",
"automating-vacuum-analyze-for-geometry-heavy-tables": "Automating VACUUM ANALYZE for Geometry-Heavy Tables",
"brin-indexes-for-append-only-spatial-tables": "BRIN Indexes for Append-Only Spatial Tables",
"covering-indexes-with-include-for-spatial-queries": "Covering Indexes with INCLUDE for Spatial Queries",
"forcing-index-scans-when-the-planner-chooses-seq-scan": "Forcing Index Scans When the Planner Chooses Seq Scan",
"keyset-pagination-for-knn-result-sets": "Keyset Pagination for KNN Result Sets",
"point-in-polygon-joins-at-scale": "Point-in-Polygon Joins at Scale",
"tile-based-bounding-box-queries-for-web-maps": "Tile-Based Bounding Box Queries for Web Maps",
"st_dwithin-vs-st_distance-for-proximity-filtering": "ST_DWithin vs ST_Distance for Proximity Filtering",
"migrating-spatial-code-from-psycopg2-to-psycopg3": "Migrating Spatial Code from psycopg2 to psycopg3",
"spatial-aggregations-with-hybrid-expressions": "Spatial Aggregations with Hybrid Expressions",
"geoalchemy2-vs-raw-wkb-when-to-use-each": "GeoAlchemy2 vs Raw WKB: When to Use Each",
"async-streaming-of-large-geometry-result-sets": "Async Streaming of Large Geometry Result Sets",
offline: "Offline",
};
const crumbs = [{ label: "Home", url: "/" }];
const parts = url.replace(/^\/|\/$/g, "").split("/").filter(Boolean);
let cumulative = "";
for (const part of parts) {
cumulative += "/" + part;
crumbs.push({ label: labels[part] || part, url: cumulative + "/" });
}
return crumbs;
});
// Cache-bust filter: appends ?v=<8-char md5> so immutable assets get a new URL on change
eleventyConfig.addFilter("assetHash", function (url) {
try {
const filePath = path.join(__dirname, url.replace(/^\//, "").split("?")[0]);
const hash = crypto.createHash("md5").update(fs.readFileSync(filePath)).digest("hex").slice(0, 8);
return `${url}?v=${hash}`;
} catch {
return url;
}
});
// Truncate filter
eleventyConfig.addFilter("truncate", function (str, len) {
if (!str) return "";
return str.length > len ? str.slice(0, len) + "…" : str;
});
// Strip the first <h1>…</h1> from rendered content (layout already shows the title)
eleventyConfig.addFilter("stripFirstH1", function (content) {
if (!content) return "";
return content.replace(/<h1[^>]*>[\s\S]*?<\/h1>/, "");
});
// ── Transforms ────────────────────────────────────────────────────────────
// Wrap tables for horizontal scroll
eleventyConfig.addTransform("wrapTables", function (content, outputPath) {
if (outputPath && outputPath.endsWith(".html")) {
return content.replace(
/<table>/g,
'<div class="table-scroll"><table>'
).replace(/<\/table>/g, "</table></div>");
}
return content;
});
// Wrap code blocks server-side to avoid CLS from runtime DOM manipulation
eleventyConfig.addTransform("wrapCodeBlocks", function (content, outputPath) {
if (!outputPath || !outputPath.endsWith(".html")) return content;
// Match the full language-annotated code block (opening through closing) and wrap it
return content.replace(
/(<pre class="language-(\w+)"><code class="language-\2">[\s\S]*?<\/code><\/pre>)/g,
(match, block, lang) =>
`<div class="code-block-wrapper"><span class="code-lang-label">${lang}</span>${block}</div>`
);
});
// ── Collections ───────────────────────────────────────────────────────────
eleventyConfig.addCollection("sections", function (collectionApi) {
return collectionApi.getFilteredByGlob("content/*/index.md").filter(
(p) => p.url.split("/").filter(Boolean).length === 1
);
});
// ── Ignore files ─────────────────────────────────────────────────────────
eleventyConfig.ignores.add("BUILD_CHECKLIST.md");
eleventyConfig.ignores.add("AGENTS.md");
eleventyConfig.ignores.add("site_description_and_requirements.md");
eleventyConfig.ignores.add("README.md");
eleventyConfig.ignores.add("wrangler.jsonc");
eleventyConfig.ignores.add("CLAUDE.md");
eleventyConfig.ignores.add("_plan/**");
// ── Config ────────────────────────────────────────────────────────────────
return {
dir: {
input: ".",
includes: "_includes",
data: "_data",
output: "_site",
},
templateFormats: ["md", "njk", "html"],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
};
};