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
48 changes: 7 additions & 41 deletions site/lib/src/components/layout/banner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,23 @@

import 'package:jaspr/jaspr.dart';

/// The information to display in the site banner,
/// as configured in the `src/data/banner.yml` file.
@immutable
final class BannerContent {
final String text;
final String linkText;
final String linkUri;
final bool newTab;

const BannerContent({
required this.text,
required this.linkText,
required this.linkUri,
this.newTab = false,
});

factory BannerContent.fromMap(Map<String, Object?> bannerData) {
final text = bannerData['text'] as String;
final link = bannerData['link'] as Map<Object?, Object?>;
final linkText = link['text'] as String;
final linkUri = link['url'] as String;
final newTab = link['newTab'] as bool? ?? false;

return BannerContent(
text: text,
linkText: linkText,
linkUri: linkUri,
newTab: newTab,
);
}
}

/// The site-wide banner.
class DashBanner extends StatelessComponent {
const DashBanner(this.content, {super.key});
const DashBanner(this.inlineHtmlContent, {super.key});

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

@override
Component build(BuildContext context) => div(
id: 'site-banner',
attributes: {'role': 'alert'},
[
p([
text(content.text),
text(' '),
a(
href: content.linkUri,
target: content.newTab ? Target.blank : null,
[text(content.linkText)],
),
raw(inlineHtmlContent),
]),
],
);
Expand Down
5 changes: 3 additions & 2 deletions site/lib/src/layouts/doc_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ class DocLayout extends FlutterDocsLayout {
currentTitle: pageTitle,
),
if (showBanner)
if (page.data['banner'] case final Map<String, Object?> bannerData)
DashBanner(BannerContent.fromMap(bannerData)),
if (siteData['bannerHtml'] case final String bannerHtml
when bannerHtml.trim().isNotEmpty)
DashBanner(bannerHtml),
div(classes: 'after-leading-content', [
if (tocData != null)
aside(id: 'side-menu', [
Expand Down
7 changes: 0 additions & 7 deletions src/data/banner.yml

This file was deleted.

7 changes: 7 additions & 0 deletions src/data/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ email: flutter-dev@googlegroups.com

showBanner: true

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

branch: main
repo:
organization: https://github.com/flutter
Expand Down
Loading