How-to & Guides · How-to

How to Integrate an External GitHub Pages Demo into an Azure Static Web App

Use one content-only child build contract and a manifest-driven parent template to publish multiple GitHub Pages projects under one Azure Static Web App domain.

Use this procedure to publish one or more independently maintained child websites under an existing Azure Static Web App (SWA) domain. The parent repository owns the page template, shared navigation, footer, routes, and deployment. Each child repository builds content and assets without its standalone site layout. The child’s normal GitHub Pages site continues to use its own template.

The checked-in implementation is a reusable pattern for public child repositories. Its first configured child is cloud-migration-demo, published at https://andyxuan.ca/cloud-migration-demo/.

Objective

Build the parent site and each child independently, then publish the child output beneath a stable parent path. Keep the browser on the parent domain. Do not use an iframe, redirect to GitHub Pages, runtime proxy, DNS change, or new Azure resource.

~mermaid flowchart LR P[Parent repository] --> M[integrated-sites.json] C1[Child repository A] --> B[Content build contract] C2[Child repository B] --> B M --> O[Parent build orchestrator] B --> O O --> T[Shared parent template and shell] T --> S[One SWA deployment artifact] S --> U[parent.example/child-a/] S --> V[parent.example/child-b/] ~

The parent builds one integrated artifact. It does not store copies of child source pages in Git.

Responsibilities

Parent repositoryChild repository
Owns the shared HTML template, site shell, navigation, and footer.Owns topic content, content styles, behavior, and assets.
Lists children, public repositories, environment refs, and URL slugs in static-web-apps/andyxuan.ca/integrated-sites.json.Implements scripts/Build-IntegratedContent.ps1 as the stable content-build entry point.
Builds each child, validates its output, and assembles pages under the slug.Keeps the default standalone build and GitHub Pages workflow unchanged.
Adds each child route to Static Web Apps fallback exclusions and lists child links from the manifest.Emits body fragments and scoped assets without its standalone header, footer, or document wrapper.

Child content contract

Every integrated child implements scripts/Build-IntegratedContent.ps1 -OutputDirectory _integration. A child using another language or framework may use this script as a thin wrapper around its normal build tools. The wrapper must produce this contract:

~text _integration/ ├── index.html # body fragment, not a full HTML document ├── content.css # styles scoped to the integration root ├── content.js # child behavior; use an empty file if unused ├── search-index.json # optional child data └── ... referenced local assets and nested fragment pages ... ~

Each generated HTML page has one data-integrated-content root and a data-page-title value. It must not contain <!doctype>, <html>, <head>, <body>, or the child site’s global header or footer. Internal links and asset paths must work after the page is published under the child slug. Avoid root-relative paths that point at the parent domain root unless that behavior is intentional.

Scope CSS to the content root so child selectors cannot restyle the parent shell. The current documentation demo uses native CSS @scope ([data-integrated-content]); another child may use an equivalent scoped build output. Child JavaScript should query within its own integration root and avoid global IDs or storage keys that collide with the parent.

The parent accepts generated HTML, CSS, JavaScript, JSON, common image and font formats, PDF and Office documents, and Draw.io diagrams. It rejects symlinks, source Markdown, .env*, .git, .github, node_modules, CNAME, and child staticwebapp.config.json files. Add another required static asset type to the parent allowlist before depending on it.

Preserve the standalone site

The normal child command remains the source for GitHub Pages. For example, cloud-migration-demo runs Build-DocsSite.ps1 with its default standalone layout. Its integration wrapper calls the same generator with -LayoutMode content. The two builds share source documents but emit different layouts.

Do not change the default build to fragments or remove the child template. Add the content mode alongside the existing standalone mode and ignore its generated _integration/ directory in the child repository.

Register a child in the parent

Add one entry to static-web-apps/andyxuan.ca/integrated-sites.json:

~json { "slug": "child-demo", "title": "Child Demo", "description": "A concise description for the page metadata.", "repository": "example-org/child-demo", "refByEnvironment": { "dev": "dev", "prod": "main" }, "sourceDirectory": "integrated-content/child-demo" } ~

Use a lowercase URL-safe slug that does not collide with an existing parent file or directory. The parent uses /child-demo/ as the public path. Add /static-web-apps/andyxuan.ca/child-demo/ to the parent repository’s .gitignore; generated content staging is covered by the existing /integrated-content/ ignore rule.

The current orchestrator clones public GitHub repositories without a token. Private child repositories need a separately designed checkout credential and permissions model; do not put a token in this manifest.

Choose refs by deployment environment

The reusable deployment workflow passes its GitHub environment to the build:

  • The dev deployment uses the child’s refByEnvironment.dev.
  • The prod deployment uses the child’s refByEnvironment.prod.

For the current demo, these refs are dev and main. This lets the parent dev hostname exercise child changes on dev, while production consumes child main. When promoting a child change, merge it to the child’s production branch before deploying the parent’s production environment.

The orchestrator logs the selected child ref and resolved commit SHA. For local development it reuses a matching sibling repository. Set INTEGRATED_SITE_SOURCE_ROOT to a directory containing child folders named by slug to use another local source root. On a CI runner without a local checkout, it clones into the ignored integration-sources/<slug> directory and refreshes that managed clone to the configured ref.

Parent build and assembly

The existing scripts/build-site.sh andyxuan.ca <dev|prod> entry point calls scripts/build-integrated-sites.mjs. For every manifest entry, the orchestrator:

  1. Resolves the source repository and environment ref.
  2. Runs the child’s Build-IntegratedContent.ps1 contract.
  3. Checks required files, allowed extensions, and symlink and source-file restrictions.
  4. Copies the generated content to the configured staging path.
  5. Calls scripts/assemble-integrated-sites.mjs to apply integrated-site.template.html to every child fragment.

The shared template loads the parent’s styles.css and site-shell.js, inserts the child fragment, then provides the parent navigation and footer. The parent Projects menu reads the same manifest, so adding a child does not require a hard-coded navigation entry.

The assembler adds /<slug>/* to the existing Static Web Apps navigation-fallback exclusions. This lets child routes bypass the parent fallback. It backs up the original staticwebapp.config.json during assembly; the deployment cleanup step restores that file and removes generated child output. Do not replace the parent config with a child config.

Updating child content

A child push does not by itself redeploy the parent SWA. The parent’s workflow_dispatch can rebuild from the configured refs. The parent workflow also accepts repository_dispatch event demo-updated; automatic cross-repository notifications require a narrowly scoped credential and a notification workflow in each child. Configure that separately if automatic parent redeployment is required. Do not assume the child Pages publish is a deployment trigger for the parent.

Validation

Before merging changes, verify both the child’s standalone and content outputs, then validate the assembled parent artifact. Run the first three commands in the child repository and the remaining commands in the parent repository:

~~~powershell ./scripts/Build-DocsSite.ps1 ./scripts/Test-DocsSite.ps1 ./scripts/Build-IntegratedContent.ps1

bash scripts/build-site.sh andyxuan.ca dev node scripts/validatestaticsites.py node scripts/clean-integrated-sites.mjs static-web-apps/andyxuan.ca ~~~

The parent’s CI deployment job performs the content build and assembly. Check that every child page has the parent shell, every generated asset stays under the child path, and the final root staticwebapp.config.json still contains the parent’s original headers and fallback rules. Validate Azure routing in the deployed dev environment before production. A local static server does not prove SWA-specific routing behavior.

Do not claim a successful build or production validation unless it was run and observed.

Rollback and maintenance

To remove a child, remove its entry from integrated-sites.json, remove its generated URL directory from .gitignore, remove any child-specific parent feature card, and deploy the parent. The Projects menu and route exclusions are generated from the manifest. Keep the child repository and GitHub Pages workflow intact.

To revert a release, revert the parent integration commit and deploy the previous parent artifact. For a child-only rollback, select a known-good child ref in the environment mapping and redeploy the parent. Do not delete or rewrite the child’s GitHub Pages branch as part of a parent rollback.