AWS Builder Center
doc2site

doc2site

Optimizing Static Site Generation with Incremental Builds

Building Doc2Site: Optimizing Static Site Generation with Incremental Builds

Introduction

Documentation is an essential part of every software project. As projects grow, maintaining documentation becomes increasingly important. However, generating and publishing documentation efficiently can introduce its own engineering challenges.
Traditional static site generation workflows often rebuild the entire website whenever a small change is introduced. For a documentation repository containing hundreds or thousands of Markdown files, this can result in unnecessary computation, longer build times, and inefficient CI/CD pipelines.
I wanted to explore a different approach: What if a documentation generator could understand what actually changed and process only those files?
That idea led to Doc2Site, a Markdown-to-static-site generator designed around incremental builds, SHA-256 content hashing, and persistent CI/CD caching.

The Problem: Redundant Computation in Static Site Generation

While exploring static site generation workflows, I identified two major inefficiencies.

1. Rebuilding Unchanged Content

In a conventional build process, modifying a single Markdown document can trigger regeneration of the entire website.
Consider a documentation repository containing 1,000 Markdown files. If only one file changes, processing all 1,000 files introduces unnecessary work.
The problem becomes more noticeable as documentation repositories grow.

2. Ephemeral CI/CD Environments

Another challenge comes from continuous integration environments.
GitHub Actions runners operate in ephemeral environments. Previous build state is not automatically available when a new workflow starts.
Even if a previous execution already generated the website, the next workflow may repeat the same work unless the necessary state is explicitly preserved.
I wanted to address both problems through a state-aware build process.

The Solution: Introducing Doc2Site

Doc2Site is a lightweight static site generator built with Node.js.
Instead of treating every build as a completely new operation, it maintains information about previously processed files and uses that information to determine whether regeneration is necessary.
The implementation revolves around three core mechanisms:
  • Incremental Builds: Only modified or newly added Markdown files undergo HTML transformation.
  • SHA-256 Content Hashing: Content changes are detected using cryptographic hashes rather than relying solely on file modification timestamps.
  • Persistent CI/CD Caching: GitHub Actions caching preserves the previous build state across workflow executions.
Together, these mechanisms reduce redundant Markdown processing and make the build pipeline more efficient.

Understanding the Architecture

The build engine follows a simple but effective sequence of operations.

Step 1: Scan the Documentation

The generator scans the source directory and identifies the available Markdown files.
These files become the input for the build process.

Step 2: Generate Content Hashes

For every Markdown file, Doc2Site generates a SHA-256 hash based on its content.
This hash acts as a fingerprint of the file.
If the content changes, its hash changes as well.

Step 3: Compare Previous and Current State

The generator compares the newly generated hashes against the previously stored hashes in  hashes.json .
This comparison helps identify three situations:
  • New files that have not been processed before.
  • Existing files whose content has changed.
  • Deleted files that no longer exist in the source directory.

Step 4: Transform Only Changed Files

When a file is new or its hash differs from the previous version, Doc2Site processes it using the Marked Markdown parser.
Unchanged files are skipped, avoiding unnecessary Markdown-to-HTML conversion.

Step 5: Synchronize the Build State

After processing, the generator updates  hashes.json  with the latest content hashes.
The generated HTML files and updated state are maintained in the output directory.
This ensures that subsequent builds can identify changes relative to the latest successful state.

How Incremental Builds Improve Efficiency

The most important design decision in Doc2Site is separating file scanning and change detection from content transformation.
Consider the following example:
Imagine a documentation repository containing 1,000 Markdown files.
During the first build, all 1,000 files need to be processed.
During the next build, suppose only five files have changed.
Instead of transforming all 1,000 documents again, Doc2Site identifies the five changed files and regenerates their corresponding HTML.
This significantly reduces redundant transformation work.
It is important to distinguish the overall build complexity from the transformation complexity.
The generator still needs to scan and hash the source files. Therefore, the overall process includes work proportional to the number of files, while the Markdown transformation workload is proportional to the number of changed files.
This distinction is important when evaluating incremental build performance.

Making Incremental Builds Work with GitHub Actions

Implementing incremental builds locally is only part of the solution.
The bigger challenge is preserving build state between CI/CD executions.
To address this, Doc2Site integrates with GitHub Actions caching.
The workflow follows this lifecycle:
  1. A new GitHub Actions workflow starts.
  1. The previous  hashes.json  state is restored from the cache.
  1. Doc2Site scans the documentation directory.
  1. SHA-256 hashes are generated and compared against the restored state.
  1. Only changed Markdown documents are transformed.
  1. The updated build state is saved for subsequent workflow executions.
  1. Generated HTML files are deployed through GitHub Pages.
This integration allows the build engine to retain useful context across otherwise independent workflow executions.
It also demonstrates how persistent caching can improve the efficiency of CI/CD pipelines.

Technology Stack

Doc2Site uses a relatively lightweight technology stack.
Technology
Purpose
Node.js
Core runtime and build engine
Marked v9
Markdown-to-HTML conversion
SHA-256
Content-based change detection
GitHub Actions
CI/CD automation
actions/cache
Persistent build-state caching
GitHub Pages
Static website hosting
I deliberately kept the implementation lightweight rather than introducing unnecessary infrastructure or dependencies.

Security and Reliability Considerations

Performance is important, but build optimization should not come at the expense of reliability.
Doc2Site also considers several implementation-level concerns:
Input Sanitization: Markdown input needs appropriate handling before generating HTML.
Path Normalization: File paths should be normalized and validated to prevent unintended filesystem access.
Deletion Detection: Removing a Markdown document should also remove its corresponding generated output.
State Synchronization: The cached hash information must accurately represent the generated content to avoid incorrect build decisions.
These considerations are important when moving from a basic script to a reusable build system.

Deployment

Doc2Site generates static HTML files that can be hosted independently of the generation process.
The current implementation integrates with GitHub Actions for automated builds and GitHub Pages for deployment.
This separates the content generation stage from the hosting stage.
Since the output consists of static assets, the architecture can also be extended to other hosting environments, including Amazon S3 with Amazon CloudFront.
That provides an interesting direction for future AWS integration.

What I Learned

Building Doc2Site helped me explore several concepts beyond basic Markdown parsing.
Some of the most valuable engineering takeaways were:
  • Why full rebuilds introduce unnecessary computational overhead.
  • How content hashing can be used for change detection.
  • How to design a state-aware build process.
  • Why ephemeral CI environments require deliberate state persistence.
  • How GitHub Actions caching can improve repeated workflow executions.
  • Why file deletion and cache synchronization are important parts of incremental build systems.
One important takeaway was that performance optimization is not always about choosing a faster algorithm. Sometimes, the biggest improvement comes from avoiding work that does not need to happen in the first place.

Future Scope: Exploring AWS-Based Deployment

Although Doc2Site currently uses GitHub Actions and GitHub Pages, its architecture provides a foundation for further experimentation.
One potential extension is integrating Amazon S3 and Amazon CloudFront.
A possible deployment architecture would look like this:
  1. GitHub Actions triggers the build pipeline.
  1. Doc2Site identifies and processes changed documentation.
  1. Generated static assets are uploaded to an Amazon S3 bucket.
  1. Amazon CloudFront distributes the content globally.
  1. Updated documentation becomes accessible through the hosted website.
This would provide an opportunity to explore cloud-based static content delivery alongside incremental build optimization.

Conclusion

Doc2Site started with a simple engineering question: why should a build system repeatedly process content that has not changed?
By combining incremental builds, SHA-256 content hashing, and persistent CI/CD caching, I built a system that avoids unnecessary Markdown transformations and makes repeated documentation builds more efficient.
The project reinforced an important engineering principle:
Efficient systems are not just about doing work faster. They are also about knowing when work is unnecessary.
I built Doc2Site to explore that principle in practice, and I look forward to extending its capabilities further.





Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article