-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathProgram.cs
More file actions
74 lines (59 loc) · 1.96 KB
/
Program.cs
File metadata and controls
74 lines (59 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Collections.Generic;
using System.IO;
using Docs;
using Docs.Logic;
using ServiceStack.Text;
namespace ConsoleUtil
{
class Program
{
public static List<Page> Pages { get; set; }
static void Main(string[] args)
{
var filePath = @"C:\src\ServiceStack.Examples\src\Docs\Pages.json";
if (File.Exists(filePath))
{
var json = File.ReadAllText(filePath);
Pages = JsonSerializer.DeserializeFromString<List<Page>>(json);
var webHostUrl = "http://servicestack.net/docs/";
foreach (var page in Pages)
{
//ReplaceOldLinks(webHostUrl, page);
var contents = page.GetContent();
contents = contents.Replace(webHostUrl, "~/");
Save(page, contents);
}
}
}
public static void ReplaceOldLinks(string baseUrl, Page srcPage)
{
var content = srcPage.GetContent();
if (content == null) return;
foreach (var page in Pages)
{
var realSrc = page.Src;
if (realSrc.EndsWith("/wiki/Home"))
realSrc = realSrc.Replace("/wiki/Home", "/wiki");
else if (realSrc.EndsWith("/blob/master/README.md"))
realSrc = realSrc.Replace("/blob/master/README.md", "");
var realSrcLink = "(" + realSrc + ")";
if (content.IndexOf(realSrcLink) == -1) continue;
var newUrl = baseUrl + page.Category.SafeName() + "/" + page.Slug;
var newUrlLink = "(" + newUrl + ")";
content = content.Replace(realSrcLink, newUrlLink);
}
content = content.Replace(
"(https://github.com/ServiceStack/ServiceStack.Redis/wiki/Caching)",
"(http://servicestack.net/docs/framework/caching-options)");
Save(srcPage, content);
}
public static void Save(Page srcPage, string contents)
{
var cateogryDir = Path.Combine(@"C:\src\ServiceStack.Examples\src\Docs", srcPage.Category.SafeName());
if (!Directory.Exists(cateogryDir))
Directory.CreateDirectory(cateogryDir);
srcPage.FilePath = Path.Combine(cateogryDir, srcPage.Slug + ".md");
File.WriteAllText(srcPage.FilePath, contents);
}
}
}