Skip to content

Commit

Permalink
Fix retrieval of main page when title is explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
WilStead committed Jan 9, 2023
1 parent 1a89ad0 commit b0b88f0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: publish
env:
VERSION: '0.18.4-preview'
VERSION: '0.18.5-preview'
PRERELEASE: true
on:
push:
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.18.5-preview
### Fixed
- Retrieval of main page when title is explicit

## 0.18.4-preview
### Fixed
- URL generation for main titles
Expand Down
21 changes: 17 additions & 4 deletions src/Models/PageTitle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,16 @@ public override string ToString()
/// Gets a copy of this instance with the specified default title, if <see cref="Title"/> is
/// currently <see langword="null"/>.
/// </summary>
/// <param name="defaultTitle">
/// The domain of the page (if any).
/// <param name="title">
/// The default title to supply if the currrent title is <see langword="null"/>.
/// </param>
/// <returns>
/// A new <see cref="PageTitle"/> with <see cref="Title"/> set to the given default if it was
/// previously <see langword="null"/>, and the same <see cref="Namespace"/> and <see
/// cref="Domain"/> as this instance.
/// </returns>
public PageTitle WithDefaultTitle(string defaultTitle)
=> new(Title ?? defaultTitle, Namespace, Domain);
public PageTitle WithDefaultTitle(string title)
=> new(Title ?? title, Namespace, Domain);

/// <summary>
/// Gets a copy of this instance with the specified <paramref name="domain"/>.
Expand Down Expand Up @@ -390,6 +390,19 @@ public PageTitle WithDefaultTitle(string defaultTitle)
/// </returns>
public PageTitle WithNamespace(string? @namespace) => new(Title, @namespace, Domain);

/// <summary>
/// Gets a copy of this instance with the specified title.
/// </summary>
/// <param name="title">
/// The title of the page (if any).
/// </param>
/// <returns>
/// A new <see cref="PageTitle"/> with <see cref="Title"/> set to the given value, and the same
/// <see cref="Namespace"/> and <see cref="Domain"/> as this instance.
/// </returns>
public PageTitle WithTitle(string? title)
=> new(title, Namespace, Domain);

internal void WriteUrl(StringWriter writer, WikiOptions wikiOptions)
{
if (!string.IsNullOrEmpty(Domain))
Expand Down
4 changes: 4 additions & 0 deletions src/WikiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,10 @@ public static async Task<Page> GetWikiPageAsync(
bool noRedirect = false,
bool exactMatchOnly = false)
{
if (title.Title?.Equals(options.MainPageTitle) == true)
{
title = title.WithTitle(null);
}
if (string.CompareOrdinal(title.Namespace, options.CategoryNamespace) == 0)
{
return await IPage<Category>
Expand Down

0 comments on commit b0b88f0

Please sign in to comment.