Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ pnpm-debug.log*

# ide
.idea/

# Local Netlify folder
.netlify
11 changes: 9 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@
"files.associations": {
"*.mdx": "markdown"
},
"tailwindCSS.experimental.configFile": "src/styles/main.css"
}
"tailwindCSS.experimental.configFile": "src/styles/main.css",
"deno.enable": true,
"deno.enablePaths": [
"netlify/edge-functions"
],
"deno.unstable": true,
"deno.importMap": ".netlify/edge-functions-import-map.json",
"deno.path": "/Users/shuvo/Library/Preferences/netlify/deno-cli/deno"
}
16 changes: 15 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { unified } from "@astrojs/markdown-remark";
import mdx from "@astrojs/mdx";
import react from "@astrojs/react";
import sitemap from "@astrojs/sitemap";
Expand Down Expand Up @@ -46,11 +47,19 @@ const fontsConfig = Object.entries(theme.fonts.font_family)
};
});

const isNetlify = process.env.NETLIFY === "true";

const { default: adapter } = isNetlify
? await import("@astrojs/netlify")
: await import("@astrojs/node");

// https://astro.build/config
export default defineConfig({
output: "server",
site: config.site.base_url ? config.site.base_url : "http://examplesite.com",
base: config.site.base_path ? config.site.base_path : "/",
trailingSlash: config.site.trailing_slash ? "always" : "never",
adapter: isNetlify ? adapter() : adapter({ mode: "standalone" }),
image: { service: sharp() },
vite: { plugins: [tailwindcss()] },
fonts: fontsConfig,
Expand All @@ -71,7 +80,12 @@ export default defineConfig({
mdx(),
],
markdown: {
remarkPlugins: [remarkToc, [remarkCollapse, { test: "Table of contents" }]],
processor: unified({
remarkPlugins: [
remarkToc,
[remarkCollapse, { test: "Table of contents" }],
],
}),
shikiConfig: { theme: "one-dark-pro", wrap: true },
},
});
64 changes: 64 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[build]
publish = "dist"
command = "pnpm build"
command = "pnpm build"

[[edge_functions]]
function = "markdown"
path = "/*"
39 changes: 39 additions & 0 deletions netlify/edge-functions/markdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function toMarkdownPath(pathname: string): string {
const path = pathname.replace(/\/$/, "") || "/";
return path === "/" ? "/index.md" : `${path}.md`;
}

export default async function handler(req: Request, context: any) {
const accept = req.headers.get("Accept") ?? "";

if (!accept.includes("text/markdown")) {
return context.next();
}

const url = new URL(req.url);
const mdPath = toMarkdownPath(url.pathname);

// Rewrite to the static .md file
const mdUrl = new URL(req.url);
mdUrl.pathname = mdPath;

const mdResponse = await context.rewrite(mdUrl.toString());

if (mdResponse && mdResponse.status === 200) {
const markdown = await mdResponse.text();
return new Response(markdown, {
status: 200,
headers: {
"Content-Type": "text/markdown; charset=utf-8",
"x-markdown-tokens": String(
Math.ceil(markdown.split(/\s+/).length * 1.3),
),
Vary: "Accept",
},
});
}

return context.next();
}

export const config = { path: "/*" };
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
},
"dependencies": {
"@astrojs/check": "0.9.8",
"@astrojs/markdown-remark": "^7.2.0",
"@astrojs/mdx": "5.0.3",
"@astrojs/netlify": "^7.0.12",
"@astrojs/node": "^10.1.3",
"@astrojs/react": "5.0.3",
"@astrojs/sitemap": "3.7.2",
"@digi4care/astro-google-tagmanager": "^1.6.0",
"@justinribeiro/lite-youtube": "^1.9.0",
"astro": "6.1.9",
"astro": "6.4.4",
"astro-auto-import": "^0.5.1",
"astro-swiper": "^2.5.0",
"date-fns": "^4.1.0",
Expand Down Expand Up @@ -53,12 +56,12 @@
"eslint": "^10.2.0",
"glob": "^13.0.6",
"node-html-parser": "^7.1.0",
"turndown": "^7.2.4",
"prettier": "^3.8.1",
"prettier-plugin-astro": "^0.14.1",
"prettier-plugin-tailwindcss": "^0.7.2",
"tailwind-bootstrap-grid": "^7.0.0",
"tailwindcss": "^4.2.2",
"turndown": "^7.2.4",
"typescript": "^6.0.2",
"wrangler": "^4.80.0"
},
Expand Down
Loading