-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathpage_source_info.dart
More file actions
58 lines (50 loc) · 1.79 KB
/
page_source_info.dart
File metadata and controls
58 lines (50 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2025 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 'package:jaspr_content/jaspr_content.dart';
/// Information about a page's source location and related URLs.
final class PageSourceInfo {
const PageSourceInfo({
required this.issueUrl,
this.sourceUrl,
});
/// The URL to create a new issue for this page.
final String issueUrl;
/// The URL to view the source of this page on GitHub.
///
/// This will be `null` if the page doesn't have an `inputPath`.
final String? sourceUrl;
}
extension PageSourceInfoExtension on Page {
/// Returns the source information for this page.
PageSourceInfo get sourceInfo {
final pageUrl = url;
final pageData = data.page;
final siteData = data.site;
final branch = siteData['branch'] as String? ?? 'main';
final repoLinks = siteData['repo'] as Map<String, Object?>? ?? {};
final repoUrl =
repoLinks['this'] as String? ?? 'https://github.com/flutter/website';
final inputPath = pageData['inputPath'] as String?;
final siteUrl = siteData['url'] as String? ?? 'https://docs.flutter.dev';
final fullPageUrl = '$siteUrl$pageUrl';
final String? pageSourceUrl;
final String issueUrl;
if (inputPath != null) {
pageSourceUrl = '$repoUrl/blob/$branch/${inputPath.replaceAll('./', '')}';
issueUrl =
'$repoUrl/issues/new?template=1_page_issue.yml&'
'page-url=$fullPageUrl&'
'page-source=$pageSourceUrl';
} else {
pageSourceUrl = null;
issueUrl =
'$repoUrl/issues/new?template=1_page_issue.yml&'
'page-url=$fullPageUrl';
}
return PageSourceInfo(
issueUrl: issueUrl,
sourceUrl: pageSourceUrl,
);
}
}