GitHub CMS Documentation
This document provides comprehensive documentation for the GitHub CMS components in Osirion.Blazor.
Table of Contents
Introduction
GitHub CMS is a content management system that uses markdown files stored in a GitHub repository as the content source. It provides:
- File-based content management
- Frontmatter support for metadata
- Caching for better performance
- Categories, tags, and directory-based organization
- Search functionality
Components
ContentList
Displays a list of content items with optional filtering.
<!-- Basic usage -->
<ContentList />
<!-- With filters -->
<ContentList Directory="blog" />
<ContentList Category="tutorials" />
<ContentList Tag="blazor" />
<ContentList FeaturedCount="3" />
<!-- With custom items -->
<ContentList ContentItems="@myItems" />
Parameters:
Directory
: Filter by directoryCategory
: Filter by categoryTag
: Filter by tagFeaturedCount
: Show featured items with limitContentItems
: Use custom items instead of fetching
ContentView
Displays a single content item.
<ContentView Path="blog/my-post.md" />
Parameters:
Path
: The path to the content item
CategoriesList
Shows a list of categories with content counts.
<CategoriesList />
TagCloud
Shows a cloud of tags with content counts.
<TagCloud MaxTags="20" />
Parameters:
MaxTags
: Maximum number of tags to display
SearchBox
Provides a search input for content.
<SearchBox Placeholder="Search content..." />
Parameters:
Placeholder
: Placeholder text for the search input
DirectoryNavigation
Creates a navigation menu based on directory structure.
<DirectoryNavigation CurrentDirectory="blog" />
Parameters:
CurrentDirectory
: The currently active directory
Models
ContentItem
Represents a content item from the repository.
Properties:
Id
: Unique identifierTitle
: Content titleAuthor
: Content authorDate
: Publication dateDescription
: Brief descriptionContent
: HTML content converted from markdownTags
: List of tagsCategories
: List of categoriesSlug
: URL-friendly identifierIsFeatured
: Whether the content is featuredFeaturedImageUrl
: URL to featured imageGitHubFilePath
: Path to file in GitHubDirectory
: Directory containing the fileCreatedDate
: Date the content was createdLastUpdatedDate
: Date the content was last updatedReadTimeMinutes
: Estimated reading time
ContentCategory
Represents a content category.
Properties:
Name
: Category nameSlugUrl
: URL-friendly identifierContentCount
: Number of items in category
ContentTag
Represents a content tag.
Properties:
Name
: Tag nameSlugUrl
: URL-friendly identifierContentCount
: Number of items with tag
Services
IGitHubCmsService
Interface for the GitHub CMS service.
Methods:
GetAllContentItemsAsync()
: Gets all content itemsGetContentItemByPathAsync(string path)
: Gets a specific content itemGetContentItemsByDirectoryAsync(string directory)
: Gets items by directoryGetCategoriesAsync()
: Gets all categoriesGetContentItemsByCategoryAsync(string category)
: Gets items by categoryGetTagsAsync()
: Gets all tagsGetContentItemsByTagAsync(string tag)
: Gets items by tagGetFeaturedContentItemsAsync(int count)
: Gets featured itemsSearchContentItemsAsync(string query)
: Searches content itemsRefreshCacheAsync()
: Refreshes the cache
Configuration
Configure the GitHub CMS service in your Program.cs
:
builder.Services.AddGitHubCms(options =>
{
options.Owner = "your-github-username";
options.Repository = "your-content-repo";
options.ContentPath = "content"; // Optional, defaults to root
options.Branch = "main";
options.ApiToken = "your-github-token"; // Optional, for private repos
options.CacheDurationMinutes = 30;
options.SupportedExtensions = new List<string> { ".md", ".markdown" };
});
Or using configuration:
builder.Services.AddGitHubCms(builder.Configuration);
With corresponding appsettings.json
:
{
"GitHubCms": {
"Owner": "your-github-username",
"Repository": "your-content-repo",
"ContentPath": "content",
"Branch": "main",
"ApiToken": "your-github-token",
"CacheDurationMinutes": 30
}
}
Examples
Blog Layout
<div class="blog-layout">
<header>
<h1>My Blog</h1>
<SearchBox Placeholder="Search blog..." />
</header>
<div class="content">
<main>
<ContentList Directory="blog" />
</main>
<aside>
<h2>Categories</h2>
<CategoriesList />
<h2>Tags</h2>
<TagCloud MaxTags="15" />
<h2>Featured</h2>
<ContentList FeaturedCount="3" />
</aside>
</div>
</div>
Content Item Page
@page "/blog/{Slug}"
<ContentView Path="@($"blog/{Slug}.md")" />
@code {
[Parameter]
public string Slug { get; set; } = string.Empty;
}
Search Results Page
@page "/search"
@inject IGitHubCmsService CmsService
<h1>Search Results</h1>
<SearchBox Placeholder="Search again..." />
@if (!string.IsNullOrEmpty(Query))
{
<p>Results for "@Query":</p>
<ContentList ContentItems="@Results" />
}
@code {
[Parameter]
[SupplyParameterFromQuery]
public string Query { get; set; } = string.Empty;
private List<ContentItem> Results { get; set; } = new();
protected override async Task OnParametersSetAsync()
{
if (!string.IsNullOrEmpty(Query))
{
Results = await CmsService.SearchContentItemsAsync(Query);
}
}
}
For more examples and detailed usage, refer to the GitHub repository.