Update Sample App to properly open links found in docs now
Have docs in release mode look at live branch of last shipped docs.
This commit is contained in:
Родитель
8fa1b43af1
Коммит
3bed168f6f
|
@ -71,7 +71,6 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
}
|
||||
|
||||
private string _cachedDocumentation = string.Empty;
|
||||
private string _cachedPath = string.Empty;
|
||||
|
||||
internal static async Task<Sample> FindAsync(string category, string name)
|
||||
{
|
||||
|
@ -149,8 +148,21 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
|
||||
public string XamlCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path set in the samples.json pointing to the doc for the sample.
|
||||
/// </summary>
|
||||
public string DocumentationUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the absolute local doc path for cached file in app.
|
||||
/// </summary>
|
||||
public string LocalDocumentationFilePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the base path segment to the current document location.
|
||||
/// </summary>
|
||||
public string RemoteDocumentationPath { get; set; }
|
||||
|
||||
public string Icon { get; set; }
|
||||
|
||||
public string BadgeUpdateVersionRequired { get; set; }
|
||||
|
@ -191,32 +203,29 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
}
|
||||
}
|
||||
|
||||
#pragma warning disable SA1009 // Doesn't like ValueTuples.
|
||||
public async Task<(string contents, string path)> GetDocumentationAsync()
|
||||
#pragma warning restore SA1009 // Doesn't like ValueTuples.
|
||||
public async Task<string> GetDocumentationAsync()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(_cachedDocumentation))
|
||||
{
|
||||
return (_cachedDocumentation, _cachedPath);
|
||||
return _cachedDocumentation;
|
||||
}
|
||||
|
||||
var filepath = string.Empty;
|
||||
var filename = string.Empty;
|
||||
var localPath = string.Empty;
|
||||
LocalDocumentationFilePath = string.Empty;
|
||||
|
||||
var docRegex = new Regex("^" + _docsOnlineRoot + "(?<branch>.+?)/docs/(?<file>.+)");
|
||||
var docMatch = docRegex.Match(DocumentationUrl);
|
||||
if (docMatch.Success)
|
||||
{
|
||||
filepath = docMatch.Groups["file"].Value;
|
||||
filename = Path.GetFileName(filepath);
|
||||
localPath = $"ms-appx:///docs/{Path.GetDirectoryName(filepath)}/";
|
||||
filename = Path.GetFileName(RemoteDocumentationPath);
|
||||
RemoteDocumentationPath = Path.GetDirectoryName(filepath);
|
||||
LocalDocumentationFilePath = $"ms-appx:///docs/{RemoteDocumentationPath}/";
|
||||
}
|
||||
|
||||
#if !DEBUG // use the docs repo in release mode
|
||||
string modifiedDocumentationUrl = $"{_docsOnlineRoot}master/docs/{filepath}";
|
||||
|
||||
_cachedPath = modifiedDocumentationUrl.Replace(filename, string.Empty);
|
||||
string modifiedDocumentationUrl = $"{_docsOnlineRoot}live/docs/{filepath}";
|
||||
|
||||
// Read from Cache if available.
|
||||
try
|
||||
|
@ -264,7 +273,6 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
{
|
||||
var result = await localDocsStream.ReadTextAsync(Encoding.UTF8);
|
||||
_cachedDocumentation = ProcessDocs(result);
|
||||
_cachedPath = localPath;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
|
@ -272,7 +280,7 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
}
|
||||
}
|
||||
|
||||
return (_cachedDocumentation, _cachedPath);
|
||||
return _cachedDocumentation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -273,10 +273,7 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
|
||||
if (CurrentSample.HasDocumentation)
|
||||
{
|
||||
#pragma warning disable SA1008 // Opening parenthesis must be spaced correctly
|
||||
var (contents, path) = await CurrentSample.GetDocumentationAsync();
|
||||
#pragma warning restore SA1008 // Opening parenthesis must be spaced correctly
|
||||
documentationPath = path;
|
||||
var contents = await CurrentSample.GetDocumentationAsync();
|
||||
if (!string.IsNullOrWhiteSpace(contents))
|
||||
{
|
||||
DocumentationTextBlock.Text = contents;
|
||||
|
@ -431,9 +428,15 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
{
|
||||
TrackingManager.TrackEvent("Link", e.Link);
|
||||
var link = e.Link;
|
||||
if (e.Link.EndsWith(".md"))
|
||||
if (link.EndsWith(".md"))
|
||||
{
|
||||
link = string.Format("https://docs.microsoft.com/en-us/windows/communitytoolkit/{0}/{1}", CurrentSample.CategoryName.ToLower(), link.Replace(".md", string.Empty));
|
||||
// Link to one of our other documents, so we'll construct the proper link here
|
||||
link = string.Format("https://docs.microsoft.com/windows/communitytoolkit/{0}/{1}", CurrentSample.RemoteDocumentationPath, link.Replace(".md", string.Empty));
|
||||
}
|
||||
else if (link.StartsWith("/"))
|
||||
{
|
||||
// We don't root our links to other docs.microsoft.com pages anymore, so we'll add it here.
|
||||
link = string.Format("https://docs.microsoft.com{0}", link);
|
||||
}
|
||||
|
||||
if (Uri.TryCreate(link, UriKind.Absolute, out Uri result))
|
||||
|
@ -450,7 +453,7 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
// Determine if the link is not absolute, meaning it is relative.
|
||||
if (!Uri.TryCreate(e.Url, UriKind.Absolute, out Uri url))
|
||||
{
|
||||
url = new Uri(documentationPath + e.Url);
|
||||
url = new Uri(CurrentSample.LocalDocumentationFilePath + e.Url);
|
||||
}
|
||||
|
||||
if (url.Scheme == "ms-appx")
|
||||
|
@ -698,7 +701,6 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
|
|||
|
||||
private PaneState _paneState;
|
||||
private bool _onlyDocumentation;
|
||||
private string documentationPath;
|
||||
|
||||
private ThemeListener _themeListener;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче