|
1 |
| -using System; |
2 | 1 | using System.IO;
|
3 | 2 | using System.Linq;
|
4 |
| -using System.Reflection; |
5 | 3 | using System.Text;
|
6 |
| -using System.Threading.Tasks; |
7 | 4 | using Build;
|
8 | 5 | using Cake.Common;
|
9 | 6 | using Cake.Common.Build;
|
|
15 | 12 | using Cake.Common.Tools.DotNet.MSBuild;
|
16 | 13 | using Cake.Common.Tools.DotNet.Pack;
|
17 | 14 | using Cake.Common.Tools.DotNet.Restore;
|
18 |
| -using Cake.Common.Tools.DotNet.Run; |
19 | 15 | using Cake.Common.Tools.DotNet.Test;
|
20 | 16 | using Cake.Core;
|
21 | 17 | using Cake.Core.IO;
|
@@ -205,17 +201,37 @@ public void RunDocfx(FilePath docfxJson)
|
205 | 201 |
|
206 | 202 | public void GenerateRedirects()
|
207 | 203 | {
|
208 |
| - var redirectProjectFile = RedirectProjectDirectory.CombineWithFilePath("RedirectGenerator.csproj"); |
209 |
| - this.Information(redirectProjectFile.FullPath); |
210 |
| - this.DotNetBuild(redirectProjectFile.FullPath); |
211 |
| - this.DotNetRun(redirectProjectFile.FullPath, new DotNetRunSettings |
| 204 | + var redirectFile = RedirectRootDirectory.CombineWithFilePath("_redirects"); |
| 205 | + if (!this.FileExists(redirectFile)) |
212 | 206 | {
|
213 |
| - WorkingDirectory = RedirectProjectDirectory, |
214 |
| - }); |
| 207 | + this.Error($"Redirect file '{redirectFile}' does not exist"); |
| 208 | + return; |
| 209 | + } |
215 | 210 |
|
216 |
| - this.Information(RedirectTargetDirectory); |
217 | 211 | this.EnsureDirectoryExists(RedirectTargetDirectory);
|
218 |
| - this.CopyFiles(RedirectSourceDirectory + "/**/*", RedirectTargetDirectory, true); |
| 212 | + |
| 213 | + var redirects = this.FileReadLines(redirectFile) |
| 214 | + .Select(line => line.Split(' ')) |
| 215 | + .Select(parts => (source: parts[0], target: parts[1])) |
| 216 | + .ToList(); |
| 217 | + |
| 218 | + foreach (var (source, target) in redirects) |
| 219 | + { |
| 220 | + var fileName = source.StartsWith("/") || source.StartsWith("\\") ? source[1..] : source; |
| 221 | + var fullFileName = RedirectTargetDirectory.CombineWithFilePath(fileName); |
| 222 | + var content = |
| 223 | + $"<!doctype html>" + |
| 224 | + $"<html lang=en-us>" + |
| 225 | + $"<head>" + |
| 226 | + $"<title>{target}</title>" + |
| 227 | + $"<link rel=canonical href='{target}'>" + |
| 228 | + $"<meta name=robots content=\"noindex\">" + |
| 229 | + $"<meta charset=utf-8><meta http-equiv=refresh content=\"0; url={target}\">" + |
| 230 | + $"</head>" + |
| 231 | + $"</html>"; |
| 232 | + this.EnsureDirectoryExists(fullFileName.GetDirectory()); |
| 233 | + this.FileWriteText(fullFileName, content); |
| 234 | + } |
219 | 235 | }
|
220 | 236 | }
|
221 | 237 |
|
|
0 commit comments