Skip to content

Commit 9f6df9d

Browse files
committed
Add blog
1 parent fa72a41 commit 9f6df9d

28 files changed

+1813
-161
lines changed

.nuke/build.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@
182182
"type": "string"
183183
}
184184
},
185+
"SkipContributorsScrape": {
186+
"type": "boolean",
187+
"description": "If enabled, skips scraping the contributors for the authors.yml file of the blog"
188+
},
185189
"Solution": {
186190
"type": "string",
187191
"description": "Path to a solution file that is automatically loaded"

eng/build/Build.Website.cs

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
using System.Linq;
88
using System.Text.Json;
99
using System.Text.Json.Serialization;
10+
using System.Threading.Tasks;
1011
using Nuke.Common;
12+
using Nuke.Common.CI.GitHubActions;
1113
using Nuke.Common.IO;
1214
using Nuke.Common.Tooling;
15+
using Octokit;
16+
using Serilog;
17+
using static Nuke.Common.Tooling.ProcessTasks;
1318
using static Nuke.Common.Tools.Git.GitTasks;
1419
using static Nuke.Common.Tools.Npm.NpmTasks;
1520

@@ -24,6 +29,10 @@ readonly record struct VersionDescription(
2429

2530
// From oldest to newest. Last one is current.
2631
const bool IsCurrentVersionPreview = true;
32+
33+
[Parameter("If enabled, skips scraping the contributors for the authors.yml file of the blog.")]
34+
readonly bool SkipContributorsScrape;
35+
2736
VersionDescription[] Versions =>
2837
[
2938
new(
@@ -45,11 +54,20 @@ readonly record struct JsonVersion(
4554
JsonPropertyName("path"),
4655
JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)
4756
]
48-
string? Path
57+
string? Path,
58+
[property: JsonPropertyName("badge")] bool Badge = true
4959
);
5060

51-
void FullBuildWebsite()
61+
async Task FullBuildWebsiteAsync()
5262
{
63+
if (!SkipContributorsScrape)
64+
{
65+
await File.WriteAllLinesAsync(
66+
RootDirectory / "sources" / "Website" / "blog" / "authors.yml",
67+
await GetAuthorsContents().ToListAsync()
68+
);
69+
}
70+
5371
(RootDirectory / "sources" / "Website" / "node_modules").CreateOrCleanDirectory();
5472
Npm("i", RootDirectory / "sources" / "Website");
5573
(TemporaryDirectory / "docs").CreateOrCleanDirectory();
@@ -107,6 +125,9 @@ version.Changelog is { } changelog
107125
$"run build -- --out-dir {RootDirectory / "artifacts" / "docs" / "Silk.NET"}",
108126
RootDirectory / "sources" / "Website"
109127
);
128+
CreateRedirectsFromOldWebsiteUrlsToNewWebsiteUrls(
129+
RootDirectory / "artifacts" / "docs" / "Silk.NET"
130+
);
110131
}
111132
finally
112133
{
@@ -131,4 +152,107 @@ string GetVersionFromChangelog(AbsolutePath path)
131152
GetVersionInfo(File.ReadAllText(path), out var ver, out var suffix, out _);
132153
return string.IsNullOrWhiteSpace(suffix) ? $"v{ver}" : $"v{ver}-{suffix}";
133154
}
155+
156+
class SocialAccount(string? provider, string? url)
157+
{
158+
public SocialAccount()
159+
: this(null, null) { }
160+
161+
public string? Provider { get; private set; } = provider;
162+
public string? Url { get; private set; } = url;
163+
}
164+
165+
async IAsyncEnumerable<string> GetAuthorsContents()
166+
{
167+
var github = new GitHubClient(
168+
new ProductHeaderValue("Silk.NET-CI"),
169+
new Octokit.Internal.InMemoryCredentialStore(
170+
new Credentials(
171+
string.IsNullOrWhiteSpace(GitHubActions.Instance?.Token)
172+
? StartProcess("gh", "auth token")
173+
.AssertZeroExitCode()
174+
.Output.First(x => x.Type == OutputType.Std)
175+
.Text.Trim()
176+
: GitHubActions.Instance.Token
177+
)
178+
)
179+
);
180+
var contributors = await github.Repository.GetAllContributors("dotnet", "Silk.NET");
181+
foreach (var contributor in contributors ?? [])
182+
{
183+
if (contributor.Login.AsSpan().ContainsAny('[', ']'))
184+
{
185+
continue;
186+
}
187+
188+
Log.Information("Fetching user info for {Login}", contributor.Login);
189+
var user = await github.User.Get(contributor.Login);
190+
if (user is null)
191+
{
192+
continue;
193+
}
194+
195+
yield return $"{user.Login}:";
196+
yield return $" name: {user.Name ?? user.Login}";
197+
yield return $" url: https://github.com/{user.Login}";
198+
yield return $" image_url: https://github.com/{user.Login}.png";
199+
yield return " page: true";
200+
Log.Information("Fetching user socials for {Login}", contributor.Login);
201+
var socials = (
202+
await github.Connection.Get<IReadOnlyList<SocialAccount>>(
203+
new Uri($"https://api.github.com/users/{user.Login}/social_accounts"),
204+
new Dictionary<string, string>(),
205+
"application/vnd.github+json"
206+
)
207+
).Body;
208+
if (socials is not { Count: > 0 })
209+
{
210+
continue;
211+
}
212+
213+
yield return " socials:";
214+
foreach (var social in socials.DistinctBy(x => x.Provider))
215+
{
216+
yield return $" {social.Provider}: \"{social.Url}\"";
217+
}
218+
}
219+
}
220+
221+
const string BaseUrl = "https://dotnet.github.io/Silk.NET/";
222+
223+
string GetRedirect(string url) =>
224+
$"""
225+
<!DOCTYPE HTML>
226+
<html>
227+
<head>
228+
<meta charset="UTF-8">
229+
<meta http-equiv="refresh" content="1; url="{BaseUrl}{url}">
230+
<script>
231+
window.location.href = "{BaseUrl}{url}"
232+
</script>
233+
<title>Redirecting...</title>
234+
</head>
235+
<body>
236+
<p>If you are not redirected automatically, <a href="{BaseUrl}{url}">click here</a>.</p>
237+
</body>
238+
</html>
239+
""";
240+
241+
void CreateRedirectsFromOldWebsiteUrlsToNewWebsiteUrls(AbsolutePath basePath)
242+
{
243+
foreach (var dirStr in Directory.GetDirectories(basePath, "*", SearchOption.AllDirectories))
244+
{
245+
var dir = (AbsolutePath)dirStr;
246+
var index = dir / "index.html";
247+
if (!index.FileExists())
248+
{
249+
continue;
250+
}
251+
252+
File.WriteAllText(
253+
dir.Parent / $"{dir.Name}.html",
254+
GetRedirect(dir.GetRelativePathTo(basePath).ToString().Replace('\\', '/'))
255+
);
256+
}
257+
}
134258
}

eng/build/Build.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,5 @@ out var releaseNotes
132132
)
133133
);
134134

135-
Target Website => CommonTarget(x => x.Executes(FullBuildWebsite));
135+
Target Website => CommonTarget(x => x.Executes(FullBuildWebsiteAsync));
136136
}

eng/build/Silk.NET.NUKE.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
<PackageReference Include="Markdig" Version="0.39.0" />
1717
<PackageReference Include="Nuke.Common" Version="9.0.3" />
1818
<PackageReference Include="Octokit" Version="13.0.1" />
19+
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
1920
</ItemGroup>
2021
</Project>

eng/submodules/silk.net-2.x

Submodule silk.net-2.x updated 69 files

sources/Website/blog/2019-05-28-first-blog-post.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

sources/Website/blog/2019-05-29-long-blog-post.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

sources/Website/blog/2021-08-01-mdx-blog-post.mdx

Lines changed: 0 additions & 24 deletions
This file was deleted.
Binary file not shown.

sources/Website/blog/2021-08-26-welcome/index.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)