Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions packages/site_shared/build.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion packages/site_shared/lib/_sass/components/_code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pre {
list-style: none;
position: relative;

// Caret at the beginning of the folding range.
// Caret at the beginning of the folding range.
span.material-symbols {
position: absolute;
cursor: pointer;
Expand Down
8 changes: 8 additions & 0 deletions packages/site_shared/lib/server_util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2026, the Flutter authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

/// Utilities meant to be used when running on the server.
library;

export 'src/utils/cache_busted_build_asset_url.dart';
50 changes: 0 additions & 50 deletions packages/site_shared/lib/src/builders/styles_hash_builder.dart

This file was deleted.

6 changes: 4 additions & 2 deletions packages/site_shared/lib/src/layouts/dash_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:jaspr_content/jaspr_content.dart';
import '../../components/common/client/cookie_notice.dart';
import '../../components/layout/banner.dart';
import '../../util.dart';
import '../utils/cache_busted_build_asset_url.dart';

/// The base Jaspr Content layout for all sites.
abstract class DashLayout implements PageLayout {
Expand Down Expand Up @@ -52,7 +53,8 @@ abstract class DashLayout implements PageLayout {
'https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0..1,0',
];

String get stylesHash;
/// The stylesheet URL for the site's built styles.
String get stylesUrl => '/assets/css/main.css';

Iterable<Component> buildExtraHead(Page page) => const [];

Expand Down Expand Up @@ -149,7 +151,7 @@ abstract class DashLayout implements PageLayout {
// Set site styles.
link(
rel: 'stylesheet',
href: '/assets/css/main.css?hash=$stylesHash',
href: cacheBustedBuildAssetUrl(stylesUrl),
),

// Set site scripts.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2026, the Flutter authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

import 'dart:convert';
import 'dart:io';

import 'package:crypto/crypto.dart';
import 'package:jaspr/server.dart';
import 'package:path/path.dart' as path;

final Map<String, String> _cacheBustedBuildAssetUrls = {};

/// The [assetUrl] with a content hash appended.
///
/// Jaspr writes web assets to `build/jaspr` before it
/// starts the static site renderer.
/// This function reads the built asset and appends a
/// truncated SHA-256 hash as a query parameter.
/// Outside static generation, it returns [assetUrl] unchanged.
///
/// If the built asset doesn't exist, throws a [FileSystemException].
/// If the built asset is empty, throws a [StateError].
String cacheBustedBuildAssetUrl(String assetUrl) {
if (!kGenerateMode) {
return assetUrl;
}

return _cacheBustedBuildAssetUrls.putIfAbsent(assetUrl, () {
final assetUri = Uri.parse(assetUrl);
final assetPath = path.joinAll([
'build',
'jaspr',
...assetUri.pathSegments,
]);
final assetFile = File(assetPath);
if (!assetFile.existsSync()) {
throw FileSystemException(
'Built asset not found. Ensure web assets are built before rendering.',
assetFile.path,
);
}

final bytes = assetFile.readAsBytesSync();
if (bytes.isEmpty) {
throw StateError('Built asset is empty: ${assetFile.path}');
}

final digest = sha256.convert(bytes);
final hash = base64Url.encode(digest.bytes).substring(0, 12);
return assetUri
.replace(
queryParameters: {
...assetUri.queryParameters,
'hash': hash,
},
)
.toString();
});
}
1 change: 0 additions & 1 deletion packages/site_shared/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ environment:
sdk: ^3.13.0-0

dependencies:
build: ^4.0.7
collection: ^1.19.1
crypto: ^3.0.7
html: ^0.15.6
Expand Down
4 changes: 0 additions & 4 deletions sites/docs/lib/src/layouts/flutter_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import '../components/layout/header.dart';
import '../components/layout/sidenav.dart';
import '../models/sidenav_model.dart';
import '../pages/markdown.dart';
import '../style_hash.dart';

/// The base Jaspr Content layout for wrapping site content.
abstract class FlutterDocsLayout extends DashLayout {
Expand All @@ -42,9 +41,6 @@ abstract class FlutterDocsLayout extends DashLayout {
@override
String get analyticsId => 'UA-67589403-1';

@override
String get stylesHash => generatedStylesHash;

String get defaultSidenav => 'default';

bool get allowBreadcrumbs => true;
Expand Down
5 changes: 0 additions & 5 deletions sites/docs/lib/src/style_hash.dart

This file was deleted.

1 change: 0 additions & 1 deletion sites/docs/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ environment:
sdk: ^3.13.0-0

dependencies:
build: ^4.0.7
collection: ^1.19.1
html: ^0.15.6
http: ^1.6.0
Expand Down
8 changes: 4 additions & 4 deletions sites/www/lib/src/layouts/default_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import 'package:jaspr/dom.dart';
import 'package:jaspr/server.dart';
import 'package:jaspr_content/jaspr_content.dart';
import 'package:site_shared/server_util.dart';

import '../components/layout/footer.dart';
import '../components/layout/header.dart';
import '../components/pages/consultants_cookie_snack.dart';
import '../models/content/banner_content.dart';
import '../style_hash.dart';
import '../utils/asset_utils.dart';
import '../utils/data_utils.dart';

Expand Down Expand Up @@ -176,9 +176,9 @@ class DefaultLayout extends PageLayout {
rel: 'stylesheet',
),

// Project Styles
const link(
href: '/main.css?hash=$generatedStylesHash',
// Set site styles.
link(
href: cacheBustedBuildAssetUrl('/main.css'),
rel: 'stylesheet',
),
],
Expand Down
5 changes: 0 additions & 5 deletions sites/www/lib/src/style_hash.dart

This file was deleted.

Loading