Skip to content

Commit

Permalink
Update to v2.3.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Jul 29, 2022
1 parent a5d902b commit b9f1913
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 49 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ You might need to fix the version when publish your website. For example:

```html
<!-- Use esm.sh, using bundled module -->
<script type="module" src="https://cdn.esm.sh/giscus@1.0.5?bundle"></script>
<script type="module" src="https://cdn.esm.sh/giscus@1.1.1?bundle"></script>

<!-- or jsDelivr -->
<script type="module" src="https://cdn.jsdelivr.net/npm/giscus@1.0.5/+esm"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/giscus@1.1.1/+esm"></script>

<!-- or Skypack, and get the pinned URL as in https://docs.skypack.dev/skypack-cdn/api-reference/pinned-urls-optimized -->
<script type="module" src="https://cdn.skypack.dev/pin/[email protected]/mode=imports,min/optimized/giscus.js"></script>
<script type="module"
src="https://cdn.skypack.dev/pin/[email protected]/mode=imports,min/optimized/giscus.js"></script>

<!-- or unpkg -->
<script type="module" src="https://unpkg.com/giscus@1.0.5?module"></script>
<script type="module" src="https://unpkg.com/giscus@1.1.1?module"></script>
```

You can also install giscus in your `wwwroot` folder with npm or other Node.js package manager, and include it like above.
Expand All @@ -66,20 +67,27 @@ Then add this component to your `.razor` files where you want the comments to ap
InputPosition="InputPosition.Bottom"
Theme="light"
Lang="en"
LazyLoading="true" />
Loading="Loading.Lazy" />
```

Or you can just add `@using GiscusBlazor` to `_Imports.razor`.

Most values of the `string` parameters can be found from the [giscus official site](https://giscus.app/).
For most of the `string`-typed parameters, you can use the values from the [giscus official site](https://giscus.app/)
directly.

## Samples

You can get some sample apps from the [samples](samples) directory, in both Blazor WebAssembly and Blazor Server.

## Changelog

### v2.3.0

- Add host support.
- Rearrange some parameters.

### v2.2.1

- Add support for lazy-loading (see [giscus official site](https://giscus.app/)).
- Removed TFM for .NET 5.0, which is now [out of support](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core#lifecycle).
- Removed TFM for .NET 5.0, which is
now [out of support](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core#lifecycle).
5 changes: 3 additions & 2 deletions samples/BlazorServerDemo/Pages/Counter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
Mapping="Mapping.PathName"
ReactionsEnabled="true"
EmitMetadata="false"
InputPosition="InputPosition.Bottom"
InputPosition="InputPosition.Top"
Theme="light"
Lang="en"
LazyLoading="true" />
Loading="Loading.Lazy"/>

@code {
private int currentCount = 0;
Expand All @@ -28,4 +28,5 @@
{
currentCount++;
}

}
3 changes: 2 additions & 1 deletion samples/BlazorServerDemo/Pages/FetchData.razor
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ else
CategoryId="DIC_kwDOG5OPrc4CBTDa"
Mapping="Mapping.Specific"
ReactionsEnabled="true"
EmitMetadata="false"
EmitMetadata="true"
InputPosition="InputPosition.Bottom"
Theme="light"
Lang="en"/>
Expand All @@ -60,4 +60,5 @@ else
{
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
}

}
6 changes: 3 additions & 3 deletions samples/BlazorWebAssemblyDemo/Pages/Counter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
Mapping="Mapping.PathName"
ReactionsEnabled="true"
EmitMetadata="false"
InputPosition="InputPosition.Bottom"
InputPosition="InputPosition.Top"
Theme="light"
Lang="en"
LazyLoading="true" />
Loading="Loading.Lazy"/>

@code {
private int currentCount = 0;
Expand All @@ -29,4 +29,4 @@
currentCount++;
}

}
}
43 changes: 23 additions & 20 deletions samples/BlazorWebAssemblyDemo/Pages/FetchData.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/fetchdata"
@inject HttpClient Http
@using GiscusBlazor
@inject HttpClient Http

<PageTitle>Weather forecast</PageTitle>

Expand All @@ -10,29 +10,31 @@

@if (forecasts == null)
{
<p><em>Loading...</em></p>
<p>
<em>Loading...</em>
</p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}
Expand All @@ -45,10 +47,10 @@ else
CategoryId="DIC_kwDOG5OPrc4CBTDa"
Mapping="Mapping.Specific"
ReactionsEnabled="true"
EmitMetadata="false"
EmitMetadata="true"
InputPosition="InputPosition.Bottom"
Theme="light"
Lang="en" />
Lang="en"/>

@code {
private WeatherForecast[]? forecasts;
Expand All @@ -66,6 +68,7 @@ else

public string? Summary { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public int TemperatureF => 32 + (int)(TemperatureC * 1.8);
}

}
8 changes: 5 additions & 3 deletions src/GiscusBlazor/Giscus.razor
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<giscus-widget repo="@Repo"
<giscus-widget host="@Host"
repo="@Repo"
repoid="@RepoId"
category="@Category"
categoryid="@CategoryId"
mapping="@Mapping.ToMappingString()"
strict="@(Strict ? "1" : "0")"
term="@Term"
reactionsenabled="@(ReactionsEnabled ? "1" : "0")"
emitmetadata="@(EmitMetadata ? "1" : "0")"
inputposition="@InputPosition"
inputposition="@InputPosition.ToPositionString()"
theme="@Theme"
lang="@Lang"
loading="@(LazyLoading ? "lazy" : "")">
loading="@Loading.ToLoadingString()">
</giscus-widget>
22 changes: 14 additions & 8 deletions src/GiscusBlazor/Giscus.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace GiscusBlazor
{
public partial class Giscus
{
[Parameter]
#if NET6_0
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public string Repo { get; set; } = null!;

[Parameter]
#if NET6_0
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public string RepoId { get; set; } = null!;

[Parameter]
Expand All @@ -22,23 +22,26 @@ public partial class Giscus
[Parameter]
public string? CategoryId { get; set; }

[Parameter]
#if NET6_0
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public Mapping Mapping { get; set; } = Mapping.PathName;

[Parameter]
public string? Term { get; set; }

[Parameter]
public bool Strict { get; set; } = false;

[Parameter]
public bool ReactionsEnabled { get; set; } = true;

[Parameter]
public bool EmitMetadata { get; set; }

[Parameter]
public InputPosition? InputPosition { get; set; }
public InputPosition InputPosition { get; set; }

[Parameter]
public string? Theme { get; set; }
Expand All @@ -47,6 +50,9 @@ public partial class Giscus
public string? Lang { get; set; }

[Parameter]
public bool LazyLoading { get; set; }
public Loading Loading { get; set; } = Loading.Eager;

[Parameter]
public string? Host { get; set; } = "https://giscus.app";
}
}
2 changes: 1 addition & 1 deletion src/GiscusBlazor/GiscusBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RepositoryUrl>https://github.com/Jisu-Woniu/giscus-blazor</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<Version>2.2.1</Version>
<Version>2.3.0</Version>
<Description>A Blazor component to embed giscus, a comments system powered by GitHub Discussions.</Description>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
6 changes: 2 additions & 4 deletions src/GiscusBlazor/InputPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ public enum InputPosition

internal static class InputPositionExtensions
{
internal static string ToPositionString(this InputPosition position)
{
return position switch
internal static string ToPositionString(this InputPosition position) =>
position switch
{
InputPosition.Bottom => "bottom",
InputPosition.Top => "top",
_ => throw new ArgumentOutOfRangeException(nameof(position))
};
}
}
}
21 changes: 21 additions & 0 deletions src/GiscusBlazor/Loading.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace GiscusBlazor
{
public enum Loading
{
Lazy,
Eager
}

internal static class LoadingExtensions
{
internal static string ToLoadingString(this Loading loading) =>
loading switch
{
Loading.Eager => "eager",
Loading.Lazy => "lazy",
_ => throw new ArgumentOutOfRangeException(nameof(loading))
};
}
}

0 comments on commit b9f1913

Please sign in to comment.