Static Site Deploy Plan
Describe a static site once and emit upload metadata, redirects, and a deploy plan from the same typed source.
Source
examples/static-site-deploy-plan/types.rank
pub Page = Object {
path: string,
source: string,
cachePolicy: `short` | `long`,
}
pub Redirect = Object {
from: string,
to: string,
status: 301 | 302,
}
pub UploadEntry = Object {
key: string,
source: string,
cacheControl: string,
}
examples/static-site-deploy-plan/main.rank
/// Generates a static-site deployment bundle from typed page and redirect data.
/// Shows one content model driving routing, caching, and upload planning.
use std::Emit
use std::Path
use std::collections::{ map }
use root::types::{ Page, Redirect, UploadEntry }
pages: [Page] = [
{
path: `/`,
source: `dist/index.html`,
cachePolicy: `short`,
},
{
path: `/pricing`,
source: `dist/pricing/index.html`,
cachePolicy: `short`,
},
{
path: `/assets/app.js`,
source: `dist/assets/app.93d2.js`,
cachePolicy: `long`,
},
{
path: `/assets/styles.css`,
source: `dist/assets/styles.a12c.css`,
cachePolicy: `long`,
},
]
redirects: [Redirect] = [
{
from: `/docs`,
to: `/pricing`,
status: 302,
},
{
from: `/home`,
to: `/`,
status: 301,
},
]
cache_control_for = |page: Page| -> string {
return match page.cachePolicy {
`short` => `public, max-age=60, stale-while-revalidate=300`,
`long` => `public, max-age=31536000, immutable`,
}
}
upload_entry_for = |page: Page| -> UploadEntry {
key = page.path == `/` ? `index.html` : page.path
return {
key: key,
source: page.source,
cacheControl: cache_control_for(page),
}
}
upload_manifest = pages |> map(|page: Page| upload_entry_for(page))
deployment_plan = {
bucket: `rank-static-site`,
invalidatePaths: pages
|> map(|page: Page| page.path),
uploadCount: 4,
}
pub main = || Emit::manifest({
entries: [
{
path: Path::join([`site`, `uploads.json`]),
format: `json`,
value: upload_manifest,
},
{
path: Path::join([`site`, `redirects.json`]),
format: `json`,
value: redirects,
},
{
path: Path::join([`site`, `deployment-plan.json`]),
format: `json`,
value: deployment_plan,
},
]
})
Output
Running the example with --file-root writes:
site/uploads.jsonsite/redirects.jsonsite/deployment-plan.json
Run it
npm run rank -- examples/static-site-deploy-plan --file-root out/static-site-deploy-plan
Key concepts
- A typed page list controls cache headers, upload keys, and CDN invalidation paths.
- Redirect data stays first-class and emits as its own artifact.
- One manifest can describe both file uploads and deployment metadata.