Skip to content

Commit

Permalink
Docs for Astro integration
Browse files Browse the repository at this point in the history
Close #50
  • Loading branch information
dahlia committed Jul 10, 2024
1 parent 5b347b2 commit e564a8c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Currently, Fedify provides the following features out of the box:
- [NodeInfo] protocol
- Special touch for interoperability with Mastodon and few other popular
fediverse software
- Integration with various web frameworks
- CLI toolchain for testing and debugging

If you want to know more about the project, please take a look at the following
Expand Down
3 changes: 2 additions & 1 deletion docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Currently, Fedify provides the following features out of the box:
- [NodeInfo] protocol
- Special touch for interoperability with Mastodon and few other popular
fediverse software
- CLI toolchain for testing and debugging
- [Integration with various web frameworks](./manual/integration.md)
- [CLI toolchain for testing and debugging](./cli.md)

If you want to know more about the project, please take a look at the following
resources:
Expand Down
32 changes: 32 additions & 0 deletions docs/manual/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,38 @@ Fedify is designed to be used together with web frameworks. This document
explains how to integrate Fedify with web frameworks.


Astro
-----

*This API is available since Fedify 0.12.0.*

[Astro] is a web framework for content-driven websites. Fedify has
the `@fedify/fedify/x/astro` module that provides a middleware to integrate
Fedify with Astro. Put the following code in your *src/middleware.ts* file:

~~~~ typescript
import type { MiddlewareHandler } from "astro";
import { createFederation } from "@fedify/fedify";
import { createMiddleware } from "@fedify/fedify/x/astro";

const federation = createFederation<string>({
// Omitted for brevity; see the related section for details.
});

export const onRequest: MiddlewareHandler = createMiddleware(
federation,
(astroContext) => "context data",
);
~~~~

> [!NOTE]
>
> Astro integration requires [on-demand server rendering][1].
[Astro]: https://astro.build/
[1]: https://docs.astro.build/en/guides/server-side-rendering/


Hono
----

Expand Down
1 change: 1 addition & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* - [NodeInfo] protocol
* - Special touch for interoperability with Mastodon and few other popular
* fediverse software
* - Integration with various web frameworks
* - CLI toolchain for testing and debugging
*
* If you want to know more about the project, please take a look at the
Expand Down
7 changes: 7 additions & 0 deletions x/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* This module contains some utilities for integrating Fedify with
* the [Astro] framework.
*
* > [!NOTE]
* >
* > Astro integration requires [on-demand server rendering][1].
*
* [Astro]: https://astro.build/
* [1]: https://docs.astro.build/en/guides/server-side-rendering/
*
* @module
* @since 0.12.0
Expand Down Expand Up @@ -34,6 +39,7 @@ type MiddlewareHandler<TAstroContext extends AstroContext> = (
* @example src/middleware.ts
* ``` typescript
* import { defineMiddleware } from "astro:middleware";
* import { createFetchOptions } from "@fedify/fedify/x/astro";
* import { federation } from "./federation"; // Import the `Federation` object
*
* export const onRequest = defineMiddleware((context, next) => {
Expand Down Expand Up @@ -106,6 +112,7 @@ export type ContextDataFactory<
* @example src/middleware.ts
* ``` typescript
* import type { MiddlewareHandler } from "astro";
* import { createMiddleware } from "@fedify/fedify/x/astro";
* import { federation } from "./federation"; // Import the `Federation` object
*
* export const onRequest: MiddlewareHandler = createMiddleware(
Expand Down

0 comments on commit e564a8c

Please sign in to comment.