-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfb8fbf
commit e3cebd8
Showing
24 changed files
with
498 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## Advanced Features | ||
|
||
This page lists some of the more advanced or less-used features of the blog software. | ||
|
||
### Shortcodes | ||
Shortcodes are markdown content that can be shown inside blog posts (like templates that can be referenced). | ||
The idea is to reuse certain shortcodes across various blog posts. | ||
If you update the shortcode, it will be updated across all those blog posts as well. | ||
|
||
For example if you have a running promotion you can add a shortcode and link it in various blog posts. Updating the shortcode (for example that it is almost sold out) will update all blog posts that reference this shortcode. | ||
|
||
#### Creating a shortcode | ||
|
||
To create a shortcode, click on "Shortcodes" in the Admin tab of the navigation bar. You can create a shortcode by adding a name in the top row and the markdown content in the editor. Clicking on an already existing shortcode will allow you to either edit the shortcode or delete it. | ||
|
||
Currently, deleting a shortcode will leave the shortcode name inside the blogpost. Therefore only delete shortcodes if you are sure that they are not used anymore. | ||
|
||
#### Using a shortcode | ||
There are two ways: | ||
1. If you know the shortcode name, just type in `[[SHORTCODENAME]]` where `SHORTCODENAME` is the name you gave the shortcode. | ||
2. Click on the more button in the editor and select "Shortcodes". This will open a dialog where you can select the shortcode you want to insert and puts it into the clipboard. | ||
|
||
### Limitations | ||
Shortcodes | ||
* are not recursive. This means that you cannot use a shortcode inside a shortcode. | ||
* are not part of the table of contents even though they might have headers. | ||
* are not part of the reading time calculation. | ||
* are only available in the content section of a blog post and not the description. | ||
* are currently only copied to the clipboard and not inserted directly into the editor at the cursor position. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
|
||
namespace LinkDotNet.Blog.Domain; | ||
|
||
public class ShortCode : Entity | ||
{ | ||
private ShortCode(string name, string markdownContent) | ||
{ | ||
Name = name; | ||
MarkdownContent = markdownContent; | ||
} | ||
|
||
public string MarkdownContent { get; private set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public void Update(string name, string content) | ||
{ | ||
ArgumentException.ThrowIfNullOrWhiteSpace(name); | ||
MarkdownContent = content; | ||
Name = name; | ||
} | ||
|
||
public static ShortCode Create(string name, string content) | ||
{ | ||
return new ShortCode(name, content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/LinkDotNet.Blog.Infrastructure/Persistence/Sql/Mapping/ShortCodeConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using LinkDotNet.Blog.Domain; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace LinkDotNet.Blog.Infrastructure.Persistence.Sql.Mapping; | ||
|
||
internal sealed class ShortCodeConfiguration : IEntityTypeConfiguration<ShortCode> | ||
{ | ||
public void Configure(EntityTypeBuilder<ShortCode> builder) | ||
{ | ||
builder.HasKey(s => s.Id); | ||
builder.Property(s => s.Id) | ||
.IsUnicode(false) | ||
.ValueGeneratedOnAdd(); | ||
builder.Property(s => s.Name) | ||
.IsRequired() | ||
.HasMaxLength(512); | ||
builder.Property(s => s.MarkdownContent) | ||
.IsRequired(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Components/CreateNewBlogPost.razor.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.extra-buttons { | ||
opacity: 0.25; | ||
} | ||
|
||
.extra-buttons:hover { | ||
opacity: 1; | ||
} |
62 changes: 62 additions & 0 deletions
62
src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Components/ShortCodeDialog.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@using LinkDotNet.Blog.Domain | ||
@inject IToastService ToastService | ||
@inject IJSRuntime JSRuntime | ||
<ModalDialog @ref="ModalDialog" Title="Select shortcode"> | ||
<div class="modal-body"> | ||
<div class="alert alert-info"> | ||
<p class="p-2"> | ||
Clicking on a shortcode, will put the shortcode into the clipboard. | ||
So you can paste it into the markdown editor. Currently it isn't possible to insert it directly into the editor at the cursor position. | ||
</p> | ||
</div> | ||
<div class="table-responsive" style="max-height: 400px; overflow-y: auto;"> | ||
<table class="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Name</th> | ||
<th scope="col">Preview</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var shortCode in ShortCodes) | ||
{ | ||
<tr @onclick="() => AddShortCode(shortCode)" style="cursor: pointer;"> | ||
<td>@shortCode.Name</td> | ||
<td> | ||
<div style="max-height: 100px; overflow-y: auto;"> | ||
@MarkdownConverter.ToMarkupString(shortCode.MarkdownContent) | ||
</div> | ||
</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-secondary" @onclick="CloseDialog">Close</button> | ||
</div> | ||
</ModalDialog> | ||
|
||
@code { | ||
private ModalDialog ModalDialog { get; set; } = default!; | ||
[Parameter] public IReadOnlyCollection<ShortCode> ShortCodes { get; set; } = []; | ||
|
||
public void Open() | ||
{ | ||
ModalDialog.Open(); | ||
StateHasChanged(); | ||
} | ||
|
||
private async Task AddShortCode(ShortCode shortCode) | ||
{ | ||
await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", $"[[{shortCode.Name}]]"); | ||
ToastService.ShowSuccess($"Shortcode {shortCode.Name} copied to clipboard"); | ||
CloseDialog(); | ||
} | ||
|
||
private void CloseDialog() | ||
{ | ||
ModalDialog.Close(); | ||
} | ||
} |
Oops, something went wrong.