From 774022cbf8d8941504c5dc282551cb3ac6f1d86b Mon Sep 17 00:00:00 2001 From: Jonathan Koren Date: Fri, 10 Jan 2020 11:13:02 -0800 Subject: [PATCH 1/2] Fix rel canonical link --- lib/src/html/template_data.dart | 8 +++++++- lib/templates/_head.html | 2 +- test/dartdoc_test.dart | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/src/html/template_data.dart b/lib/src/html/template_data.dart index 464bff60aa..4ba09304b7 100644 --- a/lib/src/html/template_data.dart +++ b/lib/src/html/template_data.dart @@ -2,7 +2,6 @@ // for details. 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:dartdoc/src/render/template_renderer.dart'; import 'package:dartdoc/src/model/model.dart'; abstract class HtmlOptions { @@ -40,6 +39,13 @@ abstract class TemplateData { String get relCanonicalPrefix => htmlOptions.relCanonicalPrefix; bool get useBaseHref => htmlOptions.useBaseHref; + String get bareHref { + if (self is Indexable) { + return (self as Indexable).href.replaceAll(HTMLBASE_PLACEHOLDER, ''); + } + return ''; + } + String _layoutTitle(String name, String kind, bool isDeprecated) => packageGraph.rendererFactory.templateRenderer .composeLayoutTitle(name, kind, isDeprecated); diff --git a/lib/templates/_head.html b/lib/templates/_head.html index 5c5e9dbcbc..3cfa7a3e67 100644 --- a/lib/templates/_head.html +++ b/lib/templates/_head.html @@ -10,7 +10,7 @@ {{ title }} {{ #relCanonicalPrefix }} - + {{ /relCanonicalPrefix}} {{#useBaseHref}}{{! TODO(jdkoren): remove when the useBaseHref option is removed.}} diff --git a/test/dartdoc_test.dart b/test/dartdoc_test.dart index 2b393bd29a..080604fce5 100644 --- a/test/dartdoc_test.dart +++ b/test/dartdoc_test.dart @@ -406,5 +406,19 @@ void main() { expect(e is DartdocFailure, isTrue); } }); + + test('rel canonical prefix does not include base href', () async { + final String prefix = 'foo.bar/baz'; + Dartdoc dartdoc = await buildDartdoc( + ['--rel-canonical-prefix', prefix], testPackageMinimumDir, tempDir); + await dartdoc.generateDocsBase(); + + File file = File(path.join(tempDir.path, 'small', 'small-library.html')); + expect(file.existsSync(), isTrue); + expect( + file.readAsStringSync(), + contains( + '')); + }); }, timeout: Timeout.factor(8)); } From bcd4142b1489a0e9517b953a1c31311ce9bd4ddb Mon Sep 17 00:00:00 2001 From: Jonathan Koren Date: Mon, 13 Jan 2020 07:43:25 -0800 Subject: [PATCH 2/2] Verify files at different levels in test --- test/dartdoc_test.dart | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/dartdoc_test.dart b/test/dartdoc_test.dart index 080604fce5..7a3339ed58 100644 --- a/test/dartdoc_test.dart +++ b/test/dartdoc_test.dart @@ -410,15 +410,20 @@ void main() { test('rel canonical prefix does not include base href', () async { final String prefix = 'foo.bar/baz'; Dartdoc dartdoc = await buildDartdoc( - ['--rel-canonical-prefix', prefix], testPackageMinimumDir, tempDir); + ['--rel-canonical-prefix', prefix], testPackageDir, tempDir); await dartdoc.generateDocsBase(); - File file = File(path.join(tempDir.path, 'small', 'small-library.html')); - expect(file.existsSync(), isTrue); + // Verify files at different levels have correct content. + File level1 = File(path.join(tempDir.path, 'ex', 'Apple-class.html')); + expect(level1.existsSync(), isTrue); expect( - file.readAsStringSync(), + level1.readAsStringSync(), contains( - '')); + '')); + File level2 = File(path.join(tempDir.path, 'ex', 'Apple', 'm.html')); + expect(level2.existsSync(), isTrue); + expect(level2.readAsStringSync(), + contains('')); }); }, timeout: Timeout.factor(8)); }