Exhaustive but simplified Akte API references.
Only the type is exported, to create an instance of AkteApp
, see defineAkteApp
.
An Akte app, ready to be interacted with.
Readonly array of Akte files registered within the app.
AkteFiles [];
Looks up the Akte file responsible for rendering the path.
(path : string ) => Match ;
Throws NotFoundError
when path could not be looked up.
Renders a match from lookup
.
(match : Match ) => Promise < string > ;
Throws NotFoundError
when match could not be rendered.
Renders all Akte files.
() => Promise < Record < string , string >> ; // Record<path, content>
Writes a map of rendered Akte files.
(args : {
outDir ?: string ; // Defaults to the app configured one, or `"dist"`
files : Record <string , string >;
}) => Promise <void> ;
Builds (renders and writes) all Akte files.
(args : {
outDir ?: string ; // Defaults to the app configured one, or `"dist"`
}) => Promise < string []> ; // Built files
Akte caches all globalData
, bulkData
, data
calls for performance. The clearCache
method allows you to clear these caches.
// Only clears global data cache unless `true`
(alsoClearFileCache ?: boolean ) => void ;
Readonly cache of the app's definition globalData
method.
Awaitable < TGlobalData > | undefined ;
Retrieves data from the app's definition globalData
method.
() => Awaitable < TGlobalData > ;
An Akte files, managing its data cascade and rendering process.
Methods and properties from the AkteFiles
class are not documented for now and to be considered internal. They are the ones that are the most likely to evolve.
If you're looking to render a single file, don't be afraid to spin up and AkteApp
, even if it's just for it.
import { defineAkteApp } from " akte" ;
import { foo } from " ./foo" ; // An `AkteFiles` instance
const app = defineAkteApp ({ files: [foo ] });
const file = await app .render (app .lookup (" /foo" ));
Creates a 404 error. To be used within Akte files definition data
function.
import { NotFoundError } from " akte" ;
new NotFoundError (path ); // Pure 404
new NotFoundError (path , { cause }); // Maybe 500
Creates an Akte app from given configuration.
import { defineAkteApp } from " akte" ;
defineAkteApp (config );
defineAkteApp <GlobalDataType >(config );
Simplified from sources~
type Config <TGlobalData > = {
// Akte files this config is responsible for.
files : AkteFiles [];
// Required when global data type is defined or inferred.
globalData ?: () => Awaitable <TGlobalData >;
// Configuration related to Akte build process.
build ?: {
// Only used by the CLI build command, defaults to `"dist"`
outDir ?: string ;
};
};
Creates an Akte files instance for a single file from a definition.
import { defineAkteFile } from " akte" ;
defineAkteFile ().from (definition );
defineAkteFile <GlobalDataType >().from (definition );
defineAkteFile <GlobalDataType , DataType >().from (definition );
Simplified from sources~
type Definition <TGlobalData , TData > = {
// Path for the Akte file, e.g. `/about` or `/sitemap.xml`
path : string ;
// Required when data type is defined.
data ?: (context : {
path : string ;
globalData : TGlobalData ;
}) => Awaitable <TData >;
// Function to render the file.
render : (context : {
path : string ;
globalData : TGlobalData ;
data : TData ;
}) => Awaitable <string >;
};
Creates an Akte files instance from a definition.
import { defineAkteFiles } from " akte" ;
defineAkteFiles ().from (definition );
defineAkteFiles <GlobalDataType >().from (definition );
defineAkteFiles <GlobalDataType , ParamsTuple >().from (definition );
defineAkteFiles <GlobalDataType , ParamsTuple , DataType >().from (definition );
Simplified from sources~
type Definition <TGlobalData , TParams , TData > = {
// Path pattern for the Akte files, e.g. `/posts/:slug` or `/**`
path : string ;
// Inferred from `bulkData` when not provided. Used for
// optimization when rendering only one file (e.g. for serverless)
data ?: (context : {
path : string ;
params : Record <TParams [number ], string >;
globalData : TGlobalData ;
}) => Awaitable <TData >;
// Required when data type is defined.
bulkData ?: (context : {
globalData : TGlobalData ;
}) => Awaitable <Record <string , TData >>;
// Function to render each file.
render : (context : {
path : string ;
globalData : TGlobalData ;
data : TData ;
}) => Awaitable <string >;
};
Akte Vite plugin factory.
import { defineConfig } from " vite" ;
import akte from " akte/vite" ;
import { app } from " ./akte.app" ;
export default defineConfig ({
plugins: [akte ({ app , ... options })],
});
Simplified from sources~
type Options <TGlobalData > = {
app : AkteApp <TGlobalData >;
// Has to be a children of Vite `root` directory.
// Defaults to `".akte"`
cacheDir ?: string ;
// On by defaults, requires `html-minifier-terser` to be installed.
minifyHTML ?: boolean : MinifyHTMLOptions ;
}
See html-minifier-terser
documentation for available options.
Akte integrates a small CLI for minimal use cases allowing you to build a given app without processing it through Vite . The CLI can be run by executing your Akte app configuration.
node akte.app.js < command>
npx tsx akte.app.ts < command>
Command Description build
Build the current Akte app
Flag Description --silent
, -s
Silence output --help
, -h
Display help --version
, -v
Display version