Skip to content

Commit 0608ae0

Browse files
committed
switched docs to running on Statiq
1 parent 873f382 commit 0608ae0

21 files changed

+278
-14
lines changed

.build/statiq-docs.cake

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// DISABLE WYAM
3+
///////////////////////////////////////////////////////////////////////////////
4+
5+
BuildParameters.Tasks.PreviewDocumentationTask.WithCriteria(() => false, "Favor Statiq over Wyam");
6+
BuildParameters.Tasks.PublishDocumentationTask.WithCriteria(() => false, "Favor Statiq over Wyam");
7+
BuildParameters.Tasks.ForcePublishDocumentationTask.WithCriteria(() => false, "Favor Statiq over Wyam");
8+
9+
///////////////////////////////////////////////////////////////////////////////
10+
// TASK DEFINITIONS
11+
///////////////////////////////////////////////////////////////////////////////
12+
13+
// No Clean task, we re-use the one provided in Wyam.cake
14+
15+
BuildParameters.Tasks.PublishDocumentationTask = Task("Publish-StatiqDocs")
16+
.IsDependentOn("Clean-Documentation")
17+
.WithCriteria(() => BuildParameters.ShouldGenerateDocumentation, "Statiq documentation has been disabled")
18+
.WithCriteria(() => DirectoryExists(BuildParameters.WyamRootDirectoryPath), "Statiq documentation directory is missing")
19+
.Does(() => {
20+
// ensure submodules are in place
21+
var gitTool = Context.Tools.Resolve("git");
22+
if (gitTool == null)
23+
{
24+
gitTool = Context.Tools.Resolve("git.exe");
25+
}
26+
if (gitTool == null)
27+
{
28+
throw new FileNotFoundException("git/git.exe could not be found!");
29+
}
30+
31+
var exitCode = Context.StartProcess(
32+
gitTool,
33+
new ProcessSettings {
34+
Arguments = "submodule init --recursive",
35+
}
36+
);
37+
38+
// Check to see if any documentation has changed
39+
var sourceCommit = GitLogTip("./");
40+
Information("Source Commit Sha: {0}", sourceCommit.Sha);
41+
var filesChanged = GitDiff("./", sourceCommit.Sha);
42+
Information("Number of changed files: {0}", filesChanged.Count);
43+
var docFileChanged = false;
44+
45+
var wyamDocsFolderDirectoryName = BuildParameters.WyamRootDirectoryPath.GetDirectoryName();
46+
47+
var pathsToTestAgainst = new List<string>() {
48+
string.Format("{0}{1}", wyamDocsFolderDirectoryName, "/input/")
49+
};
50+
51+
if (BuildParameters.ShouldDocumentSourceFiles)
52+
{
53+
// BuildParameters.WyamSourceFiles can not be used - the wyam globs are different from globs in GetFiles().
54+
pathsToTestAgainst.Add(string.Format("{0}{1}", BuildParameters.SourceDirectoryPath.FullPath, '/'));
55+
}
56+
57+
Verbose("Comparing all file-changes to the following paths:");
58+
foreach(var p in pathsToTestAgainst)
59+
{
60+
Verbose(" - "+p);
61+
}
62+
63+
foreach (var file in filesChanged)
64+
{
65+
Verbose("Changed File OldPath: {0}, Path: {1}", file.OldPath, file.Path);
66+
if (pathsToTestAgainst.Any(x => file.OldPath.Contains(x) || file.Path.Contains(x)))
67+
{
68+
docFileChanged = true;
69+
break;
70+
}
71+
}
72+
73+
if (docFileChanged)
74+
{
75+
Information("Detected that documentation files have changed, so running Statiq...");
76+
77+
Statiq();
78+
PublishStatiqDocs();
79+
}
80+
else
81+
{
82+
Information("No documentation has changed, so no need to generate documentation");
83+
}
84+
}
85+
)
86+
.OnError(exception =>
87+
{
88+
Error(exception.Message);
89+
Information("Publish-StatiqDocs Task failed, but continuing with next Task...");
90+
publishingError = true;
91+
});
92+
93+
BuildParameters.Tasks.PreviewDocumentationTask = Task("Preview-StatiqDocs")
94+
.WithCriteria(() => DirectoryExists(BuildParameters.WyamRootDirectoryPath), "Statiq documentation directory is missing")
95+
.Does(() => {
96+
Statiq("preview");
97+
});
98+
99+
100+
BuildParameters.Tasks.ForcePublishDocumentationTask = Task("Force-Publish-StatiqDocs")
101+
.IsDependentOn("Clean-Documentation")
102+
.WithCriteria(() => DirectoryExists(BuildParameters.WyamRootDirectoryPath), "Statiq documentation directory is missing")
103+
.Does(() => {
104+
Statiq();
105+
PublishStatiqDocs();
106+
}
107+
);
108+
109+
public void PublishStatiqDocs()
110+
{
111+
112+
if (!BuildParameters.CanUseWyam)
113+
{
114+
Warning("Unable to publish documentation, as not all Wyam Configuration is present");
115+
return;
116+
}
117+
118+
Statiq("deploy");
119+
}
120+
121+
// TODO: Do we need Cake.Statiq ?
122+
public void Statiq(string command = "", IDictionary<string, string> additionalSetting = null)
123+
{
124+
var statiqProj = BuildParameters.WyamRootDirectoryPath.CombineWithFilePath("Docs.csproj").FullPath; // TODO: Configurable!
125+
var logLevel = (Context.Log.Verbosity > Verbosity.Normal) ? "--log-level Trace" : string.Empty;
126+
var settings = new Dictionary<string, string>
127+
{
128+
{ "Host", BuildParameters.WebHost },
129+
{ "LinkRoot", BuildParameters.WebLinkRoot },
130+
{ "BaseEditUrl", BuildParameters.WebBaseEditUrl },
131+
{ "Title", BuildParameters.Title },
132+
{ "IncludeGlobalNamespace", "false" },
133+
{ "STATIQ_DEPLOY_OWNER", BuildParameters.RepositoryOwner },
134+
{ "STATIQ_DEPLOY_REPO_NAME", BuildParameters.RepositoryName }
135+
};
136+
137+
if (BuildParameters.ShouldDocumentSourceFiles)
138+
{
139+
settings.Add("SourceFiles", BuildParameters.WyamSourceFiles);
140+
}
141+
142+
if(additionalSetting != null)
143+
{
144+
settings = new[]{settings, additionalSetting}.SelectMany(x => x).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
145+
}
146+
147+
if((command.EqualsIgnoreCase("preview") || command.EqualsIgnoreCase("serve")) && !string.IsNullOrEmpty(BuildParameters.WebLinkRoot))
148+
{
149+
command += $" --virtual-dir={BuildParameters.WebLinkRoot}";
150+
}
151+
152+
DotNetCoreRun(statiqProj, new DotNetCoreRunSettings
153+
{
154+
EnvironmentVariables = settings,
155+
ArgumentCustomization = args=>args.Append($" -- {command} --root=\"{BuildParameters.WyamRootDirectoryPath}\" {logLevel}"),
156+
});
157+
}
158+
159+
160+
///////////////////////////////////////////////////////////////////////////////
161+
// BAKE STATIQ IN Cake.Recipe
162+
///////////////////////////////////////////////////////////////////////////////
163+
164+
BuildParameters.Tasks.PreviewTask.IsDependentOn("Preview-StatiqDocs");
165+
BuildParameters.Tasks.PublishDocsTask.IsDependentOn("Force-Publish-StatiqDocs");
166+
BuildParameters.Tasks.ContinuousIntegrationTask.IsDependentOn("Publish-StatiqDocs");

.github/workflows/publishDocs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ jobs:
1919

2020
- name: Fetch all tags and branches
2121
run: git fetch --prune --unshallow
22-
22+
2323
- name: Cache Tools
2424
uses: actions/cache@v3
2525
with:
2626
path: tools
2727
key: ${{ runner.os }}-doc-tools-${{ hashFiles('recipe.cake') }}
2828

29-
- name: Publishing documentaiton
29+
- name: Publishing documentation
3030
uses: cake-build/cake-action@v1
3131
with:
3232
script-path: recipe.cake
33-
target: Force-Publish-Documentation
33+
target: PublishDocs
3434
verbosity: Diagnostic
3535
cake-version: 1.3.0

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ docs/input/tasks/*
5252
# Wyam related
5353
config.wyam.*
5454
.idea/
55+
docs/cache/
56+
docs/output/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "docs/theme"]
2+
path = docs/theme
3+
url = https://github.com/statiqdev/Docable.git

docs/Docs.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<LanguageVersion>latest</LanguageVersion>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Statiq.Docs" Version="1.0.0-beta.5" />
13+
</ItemGroup>
14+
15+
</Project>

docs/Program.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
await Bootstrapper
2+
.Factory
3+
.CreateDocs(args)
4+
.DeployToGitHubPagesBranch(
5+
Config.FromSetting<string>("STATIQ_DEPLOY_OWNER"),
6+
Config.FromSetting<string>("STATIQ_DEPLOY_REPO_NAME"),
7+
Config.FromSetting<string>("WYAM_ACCESS_TOKEN"),
8+
Config.FromSetting<string>("WYAM_DEPLOY_BRANCH")
9+
)
10+
.RunAsync();

docs/input/assets/favicons/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# FAVICON package
2+
3+
This was all generated by using https://realfavicongenerator.net/ with
4+
https://github.com/cake-contrib/graphics/blob/3344c5e09d33dedb984edf8a362d8a3d32f7acd4/png/addin/cake-contrib-addin-large.png as the source.
20.1 KB
Loading
57.2 KB
Loading
18.8 KB
Loading

0 commit comments

Comments
 (0)