From 9fb4c954af1abde19d4e2ce484acdb39af6e466c Mon Sep 17 00:00:00 2001 From: Alan Norbauer Date: Tue, 30 Aug 2022 00:30:50 -0700 Subject: [PATCH 1/2] Add docs for non-html route encoding option --- src/pages/en/core-concepts/astro-pages.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/pages/en/core-concepts/astro-pages.md b/src/pages/en/core-concepts/astro-pages.md index 3a97151c81488..3c7ef64c6c9d0 100644 --- a/src/pages/en/core-concepts/astro-pages.md +++ b/src/pages/en/core-concepts/astro-pages.md @@ -125,6 +125,21 @@ export const get: APIRoute = ({ params, request }) => { }; ``` +If you're using SSG (static site generation) and you need to customize the encoding of the resulting file, you can return the `encoding` option in addition to the `body`. It can be any valid [`BufferEncoding`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/bdd02508ddb5eebcf701fdb8ffd6e84eabf47885/types/node/buffer.d.ts#L169) accepted by node.js' `fs.writeFile` method. For example, to produce a binary png image using SSG: + +```ts title="src/pages/image.png.ts" +import type { APIRoute } from 'astro'; + +export const get: APIRoute = ({ params, request }) => { + const buffer = ...; + return { + body: buffer.toString('binary'), + encoding: 'binary', + }; +}; + +``` + ## Custom 404 Error Page For a custom 404 error page, you can create a `404.astro` or `404.md` file in `/src/pages`. From aa83694b065a0ab28535a2f67c1f6e2d476fb02b Mon Sep 17 00:00:00 2001 From: Alan Date: Tue, 6 Sep 2022 19:25:29 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Sarah Rainsberger --- src/pages/en/core-concepts/astro-pages.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/en/core-concepts/astro-pages.md b/src/pages/en/core-concepts/astro-pages.md index 2c24e54209d95..ac69da4e2756f 100644 --- a/src/pages/en/core-concepts/astro-pages.md +++ b/src/pages/en/core-concepts/astro-pages.md @@ -130,9 +130,9 @@ export const get: APIRoute = ({ params, request }) => { }; ``` -If you're using SSG (static site generation) and you need to customize the encoding of the resulting file, you can return the `encoding` option in addition to the `body`. It can be any valid [`BufferEncoding`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/bdd02508ddb5eebcf701fdb8ffd6e84eabf47885/types/node/buffer.d.ts#L169) accepted by node.js' `fs.writeFile` method. For example, to produce a binary png image using SSG: +You can optionally return an `encoding` option in static builds. It can be any valid [`BufferEncoding`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/bdd02508ddb5eebcf701fdb8ffd6e84eabf47885/types/node/buffer.d.ts#L169) accepted by node.js' `fs.writeFile` method. For example, to produce a binary png image using SSG: -```ts title="src/pages/image.png.ts" +```ts title="src/pages/image.png.ts" {7} import type { APIRoute } from 'astro'; export const get: APIRoute = ({ params, request }) => {