Skip to content

Commit 6821910

Browse files
authored
Switch to a more flexible banner format (#12676)
Switch from defining the banner in `src/data/banner.yml` to the `bannerHtml` field in the `src/data/site.yml` banner alongside `showBanner`. I'm not sure this is the solution I want to use long term, but it works for now.
1 parent ae1d177 commit 6821910

File tree

4 files changed

+17
-50
lines changed

4 files changed

+17
-50
lines changed

site/lib/src/components/layout/banner.dart

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,23 @@
44

55
import 'package:jaspr/jaspr.dart';
66

7-
/// The information to display in the site banner,
8-
/// as configured in the `src/data/banner.yml` file.
9-
@immutable
10-
final class BannerContent {
11-
final String text;
12-
final String linkText;
13-
final String linkUri;
14-
final bool newTab;
15-
16-
const BannerContent({
17-
required this.text,
18-
required this.linkText,
19-
required this.linkUri,
20-
this.newTab = false,
21-
});
22-
23-
factory BannerContent.fromMap(Map<String, Object?> bannerData) {
24-
final text = bannerData['text'] as String;
25-
final link = bannerData['link'] as Map<Object?, Object?>;
26-
final linkText = link['text'] as String;
27-
final linkUri = link['url'] as String;
28-
final newTab = link['newTab'] as bool? ?? false;
29-
30-
return BannerContent(
31-
text: text,
32-
linkText: linkText,
33-
linkUri: linkUri,
34-
newTab: newTab,
35-
);
36-
}
37-
}
38-
397
/// The site-wide banner.
408
class DashBanner extends StatelessComponent {
41-
const DashBanner(this.content, {super.key});
9+
const DashBanner(this.inlineHtmlContent, {super.key});
4210

43-
final BannerContent content;
11+
/// The raw, inline HTML content to render in the banner.
12+
///
13+
/// This should only be sourced from managed content,
14+
/// such as our checked-in data files.
15+
final String inlineHtmlContent;
4416

4517
@override
4618
Component build(BuildContext context) => div(
4719
id: 'site-banner',
4820
attributes: {'role': 'alert'},
4921
[
5022
p([
51-
text(content.text),
52-
text(' '),
53-
a(
54-
href: content.linkUri,
55-
target: content.newTab ? Target.blank : null,
56-
[text(content.linkText)],
57-
),
23+
raw(inlineHtmlContent),
5824
]),
5925
],
6026
);

site/lib/src/layouts/doc_layout.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class DocLayout extends FlutterDocsLayout {
4747
currentTitle: pageTitle,
4848
),
4949
if (showBanner)
50-
if (page.data['banner'] case final Map<String, Object?> bannerData)
51-
DashBanner(BannerContent.fromMap(bannerData)),
50+
if (siteData['bannerHtml'] case final String bannerHtml
51+
when bannerHtml.trim().isNotEmpty)
52+
DashBanner(bannerHtml),
5253
div(classes: 'after-leading-content', [
5354
if (tocData != null)
5455
aside(id: 'side-menu', [

src/data/banner.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/data/site.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ email: [email protected]
55

66
showBanner: true
77

8+
# The raw, inline HTML to display in the banner.
9+
# Is automatically wrapped in a paragraph tag.
10+
bannerHtml: >-
11+
Don't miss the live Flutter and Dart Q&A happening
12+
today, November 12 at 11am PST.
13+
<a href="https://www.youtube.com/watch?v=RTb3gP4p5bw" target="_blank" rel="noopener">Join us!</a>
14+
815
branch: main
916
repo:
1017
organization: https://github.com/flutter

0 commit comments

Comments
 (0)