Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs/source/contribute/on-the-web.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
title: Contribute on the web
---

:::{warning}
This feature is not supported yet. See [#171](https://github.com/elastic/docs-builder/issues/171) for more information.
:::

1. On the right side of the page you want to edit, select **Edit this page**.
1. Do something on GitHub.
1. Take the dog for a walk.
Expand Down
32 changes: 28 additions & 4 deletions src/Elastic.Markdown/IO/Discovery/GitCheckoutInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ namespace Elastic.Markdown.IO.Discovery;

public record GitCheckoutInformation
{
private string? _repositoryName;

private static GitCheckoutInformation Unavailable { get; } = new()
{
Branch = "unavailable",
Remote = "unavailable",
Ref = "unavailable"
Ref = "unavailable",
RepositoryName = "unavailable"
};

[JsonPropertyName("branch")]
Expand All @@ -26,14 +29,27 @@ public record GitCheckoutInformation
[JsonPropertyName("ref")]
public required string Ref { get; init; }

[JsonIgnore]
public string? RepositoryName
{
get => _repositoryName ??= Remote.Split('/').Last();
set => _repositoryName = value;
}

// manual read because libgit2sharp is not yet AOT ready
public static GitCheckoutInformation Create(IFileSystem fileSystem)
{
// filesystem is not real so return a dummy
if (fileSystem is not FileSystem)
{
var fakeRef = Guid.NewGuid().ToString().Substring(0, 16);
return new GitCheckoutInformation { Branch = $"test-{fakeRef}", Remote = "elastic/docs-builder", Ref = fakeRef, };
return new GitCheckoutInformation
{
Branch = $"test-{fakeRef}",
Remote = "elastic/docs-builder",
Ref = fakeRef,
RepositoryName = "docs-builder"
};
}

var gitConfig = Git(".git/config");
Expand Down Expand Up @@ -66,7 +82,15 @@ public static GitCheckoutInformation Create(IFileSystem fileSystem)
if (string.IsNullOrEmpty(remote))
remote = Environment.GetEnvironmentVariable("GITHUB_REPOSITORY") ?? "elastic/docs-builder-unknown";

return new GitCheckoutInformation { Ref = gitRef, Branch = branch, Remote = remote };
remote = remote.AsSpan().TrimEnd(".git").ToString();

return new GitCheckoutInformation
{
Ref = gitRef,
Branch = branch,
Remote = remote,
RepositoryName = remote.Split('/').Last()
};

IFileInfo Git(string path) => fileSystem.FileInfo.New(Path.Combine(Paths.Root.FullName, path));

Expand All @@ -80,7 +104,7 @@ string BranchTrackingRemote(string b, IniFile c)
if (!sections.Contains(branchSection))
return string.Empty;

var remoteName = ini.GetSetting(branchSection, "remote");
var remoteName = ini.GetSetting(branchSection, "remote")?.Trim();

var remoteSection = $"remote \"{remoteName}\"";

Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.Markdown/IO/DocumentationSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class DocumentationSet
public IDirectoryInfo SourcePath { get; }
public IDirectoryInfo OutputPath { get; }

public string RelativeSourcePath { get; }

public DateTimeOffset LastWrite { get; }

public ConfigurationFile Configuration { get; }
Expand All @@ -31,6 +33,7 @@ public DocumentationSet(BuildContext context)
Context = context;
SourcePath = context.SourcePath;
OutputPath = context.OutputPath;
RelativeSourcePath = Path.GetRelativePath(Paths.Root.FullName, SourcePath.FullName);
Configuration = new ConfigurationFile(context.ConfigurationPath, SourcePath, context);

MarkdownParser = new MarkdownParser(SourcePath, context, GetMarkdownFile, Configuration);
Expand Down
8 changes: 7 additions & 1 deletion src/Elastic.Markdown/Slices/HtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public async Task<string> RenderLayout(MarkdownFile markdown, Cancel ctx = defau

var previous = DocumentationSet;

var remote = DocumentationSet.Context.Git.RepositoryName;
var branch = DocumentationSet.Context.Git.Branch;
var path = Path.Combine(DocumentationSet.RelativeSourcePath, markdown.RelativePath);
var editUrl = $"https://github.com/elastic/{remote}/edit/{branch}/{path}";

var slice = Index.Create(new IndexViewModel
{
Title = markdown.Title ?? "[TITLE NOT SET]",
Expand All @@ -56,7 +61,8 @@ public async Task<string> RenderLayout(MarkdownFile markdown, Cancel ctx = defau
CurrentDocument = markdown,
NavigationHtml = navigationHtml,
UrlPathPrefix = markdown.UrlPathPrefix,
Applies = markdown.YamlFrontMatter?.AppliesTo
Applies = markdown.YamlFrontMatter?.AppliesTo,
GithubEditUrl = editUrl
});
return await slice.RenderAsync(cancellationToken: ctx);
}
Expand Down
1 change: 1 addition & 0 deletions src/Elastic.Markdown/Slices/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CurrentDocument = Model.CurrentDocument,
NavigationHtml = Model.NavigationHtml,
UrlPathPrefix = Model.UrlPathPrefix,
GithubEditUrl = Model.GithubEditUrl
};
}
<section id="elastic-docs-v3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ul>
</div>
<div class="edit-this-page">
<a href="https://github.com/elastic/markitpy-samples/blob/master/docs/source/index.md">Edit this page</a>
<a href="@Model.GithubEditUrl">Edit this page</a>
</div>
</div>
</aside>
Expand Down
2 changes: 2 additions & 0 deletions src/Elastic.Markdown/Slices/_ViewModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class IndexViewModel
public required MarkdownFile CurrentDocument { get; init; }
public required string NavigationHtml { get; init; }
public required string? UrlPathPrefix { get; init; }
public required string? GithubEditUrl { get; init; }
public required Deployment? Applies { get; init; }
}

Expand All @@ -27,6 +28,7 @@ public class LayoutViewModel
public required MarkdownFile CurrentDocument { get; init; }
public required string NavigationHtml { get; set; }
public required string? UrlPathPrefix { get; set; }
public required string? GithubEditUrl { get; set; }

private MarkdownFile[]? _parents;
public MarkdownFile[] Parents
Expand Down
3 changes: 3 additions & 0 deletions tests/Elastic.Markdown.Tests/DocSet/LinkReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ public void Create()
git.Branch.Should().NotContain(git.Ref);
git.Ref.Should().NotBeNullOrWhiteSpace();
git.Remote.Should().NotBeNullOrWhiteSpace();
git.Remote.Should().NotContain("unknown");
git.RepositoryName.Should().NotContain(".git");
git.Remote.Should().NotContain(".git");
}
}
Loading