Skip to content

Commit dfc4084

Browse files
authored
Fix: Build site for production (#1517)
1 parent 8a47cc4 commit dfc4084

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145
- name: Fetch Dart dependencies
146146
run: dart pub get
147147
- name: Build site
148-
run: dart run flutter_site build
148+
run: dart run flutter_site build --release
149149
- name: Translated (docs.flutter.cn)
150150
run: bash tool/translator/build.sh
151151
shell: bash

.github/workflows/stage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Fetch Dart dependencies
4040
run: dart pub get
4141
- name: Build site
42-
run: dart run flutter_site build
42+
run: dart run flutter_site build --release
4343
- name: Translated (docs.flutter.cn)
4444
run: bash tool/translator/build.sh
4545
shell: bash

src/_data/site.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ email: [email protected]
66
google_analytics_id: UA-122680122-1
77
# google_site_verification: HFqxhSbf9YA_0rBglNLzDiWnrHiK_w4cqDh2YD2GEY4
88
google_tag_manager_id: G-HPSFTRXK91
9+
baidu_analytics_id: c50919183c6e001b47301f55de682929
910
default_share_image: /assets/images/cn/flutter-cn-logo.png
1011

1112

src/_layouts/base.html

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
<link rel="preconnect" href="https://fonts.googleapis.cn">
1616
<link rel="preconnect" href="https://fonts.gstatic.cn" crossorigin>
1717
{% endunless -%}
18+
19+
{%- if isProduction == true -%}
1820
<!-- Starting the Analysis Code -->
1921
<!-- Google tag (gtag.js) -->
20-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-HPSFTRXK91"></script>
22+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_tag_manager_id }}"></script>
2123
<script>
2224
window.dataLayer = window.dataLayer || [];
2325
function gtag(){dataLayer.push(arguments);}
@@ -28,12 +30,13 @@
2830
var _hmt = _hmt || [];
2931
(function() {
3032
var hm = document.createElement("script");
31-
hm.src = "https://hm.baidu.com/hm.js?c50919183c6e001b47301f55de682929";
33+
hm.src = "https://hm.baidu.com/hm.js?{{ site.baidu_analytics_id }}";
3234
var s = document.getElementsByTagName("script")[0];
3335
s.parentNode.insertBefore(hm, s);
3436
})();
3537
</script>
3638
<!-- Ending the Analysis Code -->
39+
{% endif -%}
3740

3841
{% assign desc = description | default: site.description | strip_html | strip_newlines | truncate: 160 -%}
3942
{% unless desc and desc != '' or page.url contains '/posts' or page.url contains '/community' -%}
@@ -81,13 +84,14 @@
8184

8285
<!-- {% render cookie-notice.html %}-->
8386

84-
87+
{%- if isProduction == true -%}
8588
<noscript>
8689
<iframe
8790
src="https://www.googletagmanager.com/ns.html?id={{ site.google_tag_manager_id }}"
8891
height="0" width="0" style="display:none;visibility:hidden">
8992
</iframe>
9093
</noscript>
94+
{% endif -%}
9195

9296

9397
<div id="overlay-under-drawer"></div>

tool/flutter_site/lib/src/commands/build.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ final class BuildSiteCommand extends Command<int> {
3737
const ['eleventy'],
3838
environment: {
3939
'PRODUCTION': '$productionRelease',
40-
'OPTIMIZE': '$productionRelease',
40+
// docs.flutter.cn 为了翻译工具 (tool/translator) 格式调整和解析,暂不需要优化(压缩 HTML 结构等)
41+
'OPTIMIZE': 'false', // '$productionRelease'
4142
},
4243
);
4344

0 commit comments

Comments
 (0)