Osirion.Blazor.Cms.Core 2.1.3

dotnet add package Osirion.Blazor.Cms.Core --version 2.1.3
                    
NuGet\Install-Package Osirion.Blazor.Cms.Core -Version 2.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Osirion.Blazor.Cms.Core" Version="2.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Osirion.Blazor.Cms.Core" Version="2.1.3" />
                    
Directory.Packages.props
<PackageReference Include="Osirion.Blazor.Cms.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Osirion.Blazor.Cms.Core --version 2.1.3
                    
#r "nuget: Osirion.Blazor.Cms.Core, 2.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Osirion.Blazor.Cms.Core&version=2.1.3
                    
Install Osirion.Blazor.Cms.Core as a Cake Addin
#tool nuget:?package=Osirion.Blazor.Cms.Core&version=2.1.3
                    
Install Osirion.Blazor.Cms.Core as a Cake Tool

Osirion.Blazor.Cms.Core

NuGet License

Core content management abstractions and base implementations for the Osirion.Blazor ecosystem. This package provides the foundation for building content providers and content management functionality.

Features

  • Provider Abstractions: Base interfaces and classes for content providers
  • Content Model: Rich content model with metadata support
  • SSR Compatible: Designed for Server-Side Rendering and Static SSG
  • Multi-Platform: Supports .NET 8 and .NET 9
  • Content Queries: Powerful filtering and search capabilities
  • Markdown Processing: Base Markdown parsing and rendering utilities
  • Caching Support: Efficient content delivery with built-in caching abstractions

Installation

dotnet add package Osirion.Blazor.Cms.Core

Usage

The Core package is primarily for building content providers. End users should typically use a concrete implementation like Osirion.Blazor.Cms instead.

Creating Custom Providers

Inherit from ContentProviderBase to create your own content provider:

using Osirion.Blazor.Cms.Core;
using Osirion.Blazor.Cms.Core.Models;
using Osirion.Blazor.Cms.Core.Providers;

public class CustomProvider : ContentProviderBase
{
    public CustomProvider(ILogger<CustomProvider> logger, IMemoryCache memoryCache) 
        : base(logger, memoryCache)
    {
    }

    public override string ProviderId => "custom";
    public override string DisplayName => "Custom Provider";
    public override bool IsReadOnly => true;

    public override async Task<IReadOnlyList<ContentItem>> GetAllItemsAsync(CancellationToken cancellationToken = default)
    {
        // Implement your logic to retrieve all content items
        var items = new List<ContentItem>();
        
        // Add caching if desired
        return await CacheItemsAsync(items, "all_items", cancellationToken);
    }

    public override async Task<ContentItem?> GetItemByPathAsync(string path, CancellationToken cancellationToken = default)
    {
        // Implement your logic to retrieve a specific content item
        
        // Use caching for better performance
        return await CacheItemAsync(
            async () => await FetchItemByPathAsync(path), 
            $"item_{path}", 
            cancellationToken);
    }

    public override async Task<IReadOnlyList<ContentItem>> GetItemsByQueryAsync(ContentQuery query, CancellationToken cancellationToken = default)
    {
        // Implement querying logic
        var items = await GetAllItemsAsync(cancellationToken);
        
        // Apply query filters
        return ApplyQuery(items, query);
    }
    
    private async Task<ContentItem?> FetchItemByPathAsync(string path)
    {
        // Your custom implementation for fetching content
        return null;
    }
}

Registering Custom Providers

Register your custom provider in Program.cs:

builder.Services.AddOsirionContent(content => {
    content.AddProvider<CustomProvider>();
});

Content Model

The core content model includes:

public class ContentItem
{
    // Content identification
    public string Path { get; set; } = string.Empty;
    public string Directory { get; set; } = string.Empty;
    public string Filename { get; set; } = string.Empty;
    
    // Content data
    public string RawContent { get; set; } = string.Empty;
    public string ProcessedContent { get; set; } = string.Empty;
    public Dictionary<string, object> Metadata { get; set; } = new();
    
    // Common metadata properties
    public string Title { get; set; } = string.Empty;
    public string Description { get; set; } = string.Empty;
    public DateTime? Date { get; set; }
    public string Author { get; set; } = string.Empty;
    public List<string> Categories { get; set; } = new();
    public List<string> Tags { get; set; } = new();
    public string Slug { get; set; } = string.Empty;
    public bool IsFeatured { get; set; }
    public string FeaturedImage { get; set; } = string.Empty;
    
    // Provider-specific data
    public string ProviderId { get; set; } = string.Empty;
    public Dictionary<string, object> ProviderMetadata { get; set; } = new();
}

Content Queries

The ContentQuery class provides a powerful way to filter and search content:

var query = new ContentQuery
{
    Directory = "blog",
    Category = "tutorials",
    Tag = "blazor",
    Author = "Jane Developer",
    SearchQuery = "blazor components",
    FromDate = new DateTime(2025, 1, 1),
    ToDate = DateTime.Now,
    Count = 10,
    Skip = 0,
    SortBy = SortField.Date,
    SortDirection = SortDirection.Descending,
    IsFeatured = true,
    HasFeaturedImage = true
};

Caching Helper Methods

The base class provides helper methods for caching:

// Cache a single item
var item = await CacheItemAsync(
    fetchFunction: async () => await GetItemInternalAsync(id),
    cacheKey: $"item_{id}",
    cancellationToken: cancellationToken,
    absoluteExpirationMinutes: 60);

// Cache a collection of items
var items = await CacheItemsAsync(
    items: await FetchAllItemsInternalAsync(),
    cacheKey: "all_items",
    cancellationToken: cancellationToken,
    absoluteExpirationMinutes: 60);

Core Interfaces

IContentProvider

public interface IContentProvider
{
    string ProviderId { get; }
    string DisplayName { get; }
    bool IsReadOnly { get; }
    
    Task<IReadOnlyList<ContentItem>> GetAllItemsAsync(CancellationToken cancellationToken = default);
    Task<ContentItem?> GetItemByPathAsync(string path, CancellationToken cancellationToken = default);
    Task<IReadOnlyList<ContentItem>> GetItemsByQueryAsync(ContentQuery query, CancellationToken cancellationToken = default);
    Task<IReadOnlyList<string>> GetDirectoriesAsync(CancellationToken cancellationToken = default);
    Task<IReadOnlyList<string>> GetCategoriesAsync(CancellationToken cancellationToken = default);
    Task<IReadOnlyList<string>> GetTagsAsync(CancellationToken cancellationToken = default);
}

IContentTransformer

public interface IContentTransformer
{
    Task<string> TransformAsync(string content, ContentItem item);
}

IFrontmatterParser

public interface IFrontmatterParser
{
    (string content, Dictionary<string, object> metadata) Parse(string rawContent);
}

Extension Points

Content Transformers

Create custom content transformers to modify content before rendering:

public class ExternalLinkTransformer : IContentTransformer
{
    public Task<string> TransformAsync(string content, ContentItem item)
    {
        // Add target="_blank" to external links
        var transformed = Regex.Replace(
            content,
            @"<a\s+href=""(https?://[^""]*)""",
            @"<a href=""$1"" target=""_blank"" rel=""noopener noreferrer"""
        );
        
        return Task.FromResult(transformed);
    }
}

Frontmatter Parsers

Implement custom frontmatter parsers:

public class CustomFrontmatterParser : IFrontmatterParser
{
    public (string content, Dictionary<string, object> metadata) Parse(string rawContent)
    {
        // Your custom frontmatter parsing logic
        return (content, metadata);
    }
}

Working with Markdown

The Core package includes base Markdown processing capabilities:

// Parse Markdown with default settings
var processor = new MarkdownProcessor();
var processed = await processor.ProcessAsync(markdownContent);

// Configure Markdown with specific options
services.Configure<MarkdownOptions>(options => {
    options.UseEmphasisExtras = true;
    options.UseSmartyPants = true;
    options.UseTaskLists = true;
});

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Osirion.Blazor.Cms.Core:

Package Downloads
Osirion.Blazor.Cms.Web

Front CMS module for Osirion.Blazor - Provides cms management with provider pattern.

Osirion.Blazor.Cms.Admin

Content Management System (CMS) Administration module for Osirion.Blazor, providing a robust, flexible admin interface for managing content across different providers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.3 72 5/31/2025
2.1.2 73 5/31/2025
2.1.1 157 5/20/2025
2.1.0 158 5/19/2025