forked from dotnet/docfx
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add redirection document type (dotnet#8892)
- Loading branch information
Showing
7 changed files
with
273 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{!Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license.}} | ||
<!DOCTYPE html> | ||
<html {{#_lang}}lang="{{_lang}}"{{/_lang}}> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="refresh" content="0;URL='{{redirect_url}}'"> | ||
</head> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
test/Microsoft.DocAsCode.Build.Engine.Tests/PostProcessors/SitemapGeneratorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.DocAsCode.Plugins; | ||
using Microsoft.DocAsCode.Tests.Common; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
using System.Xml.Linq; | ||
|
||
using DocumentType = Microsoft.DocAsCode.DataContracts.Common.Constants.DocumentType; | ||
|
||
namespace Microsoft.DocAsCode.Build.Engine.Tests; | ||
|
||
[Collection("docfx STA")] | ||
public class SitemapGeneratorTests : TestBase | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
|
||
public SitemapGeneratorTests(ITestOutputHelper output) | ||
: base() | ||
{ | ||
_output = output; | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
base.Dispose(); | ||
} | ||
|
||
[Fact] | ||
public void TestSitemapGenerator() | ||
{ | ||
// Arrange | ||
var sitemapGenerator = new SitemapGenerator(); | ||
var manifest = new Manifest(new[] | ||
{ | ||
// Included items | ||
GetManifestItem(DocumentType.Conceptual), | ||
GetManifestItem(DocumentType.ManagedReference), | ||
GetManifestItem(DocumentType.Resource), | ||
GetManifestItem("Dashboard"), | ||
|
||
// Skipped items | ||
GetManifestItem(DocumentType.Toc), | ||
GetManifestItem(DocumentType.Redirection), | ||
GetManifestItem(DocumentType.Conceptual, outputFileExtension: ".txt"), // No HTML output file | ||
} | ||
) | ||
{ | ||
SitemapOptions = new SitemapOptions | ||
{ | ||
BaseUrl = "https://example.com", | ||
Priority = 1, | ||
ChangeFrequency = PageChangeFrequency.Daily, | ||
LastModified = DateTime.UtcNow | ||
} | ||
}; | ||
|
||
var outputFolder = GetRandomFolder(); | ||
var sitemapPath = Path.Combine(outputFolder, "sitemap.xml"); | ||
|
||
// Act | ||
manifest = sitemapGenerator.Process(manifest, outputFolder); | ||
|
||
// Assert | ||
Assert.Equal("https://example.com/", manifest.SitemapOptions.BaseUrl); | ||
Assert.True(File.Exists(sitemapPath)); | ||
|
||
var sitemap = XDocument.Load(sitemapPath); | ||
var ns = sitemap.Root.Name.Namespace; | ||
var urls = sitemap.Root.Elements(ns + "url").ToArray(); | ||
Assert.True(urls.Length == 4); | ||
|
||
// URLs are ordered based on HTML output's RelativePath. | ||
Assert.EndsWith("/Conceptual.html", urls[0].Element(ns + "loc").Value); | ||
Assert.EndsWith("/Dashboard.html", urls[1].Element(ns + "loc").Value); | ||
Assert.EndsWith("/ManagedReference.html", urls[2].Element(ns + "loc").Value); | ||
Assert.EndsWith("/Resource.html", urls[3].Element(ns + "loc").Value); | ||
} | ||
|
||
private static ManifestItem GetManifestItem(string documentType, string outputFileExtension = ".html") | ||
{ | ||
var result = new ManifestItem | ||
{ | ||
DocumentType = documentType, | ||
SourceRelativePath = documentType + ".dummy" | ||
}; | ||
|
||
if (outputFileExtension != null) | ||
{ | ||
result.OutputFiles.Add(outputFileExtension, new OutputFileInfo | ||
{ | ||
RelativePath = documentType + outputFileExtension, | ||
}); | ||
} | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.