Popular blog tags

How to Create a Miniblog.Core Project with .Net 6.x step by step

Published

Miniblog.Core:使用ASP.NET Core 的新博客引擎

MiniBlog.Core是一个基于ASP.NET Core 2.0构建的全新强大的博客平台,可跨设备提供出色的阅读体验。它通过遵循最新的Web开发最佳实践来实现这一目标,包括一流的性能,可访问性,可读性,搜索引擎优化,使用移动优先策略的社交网络集成。

查看演示站点并查看源代码。您还可以通过安装ASP.NET核心模板包将Miniblog.Core作为Visual Studio的项目模板。

github.com:https://github.com/iaspnetcore/MiniBlog.Core

Live demo: https://miniblogcore.azurewebsites.net/
Username: demo
Password: demo

miniblog.core

 

Table of Contents

 

Features

 

Features

100% responsive and clean theme

Optimized for mobile devices

Minimal design

Valid HTML5 code

Post sharing

Supports Disqus Comments

Supports Google Analytics

Google Fonts

 

vs2022

64 bit windows 10

 

Create a Miniblog.Core Project 

我想创建一个基于ASP.NET Core的新博客引擎,它将利用现代浏览器为访问者和作者创造最佳体验。这意味着博客必须加载非常快,提供良好的阅读体验,在所有类型的设备上看起来很棒,并自动处理社交媒体集成和搜索引擎优化等所有技术内容。

step 1: Create a Miniblog.Core Project ( Asp .net core web with views and controller)

 

step 2: Add global.json

path D:\developer_mini_core\src\Miniblog.Core\global.json

{
  "sdk": {
    "version": "6.0.100-rc.2.21505.57"
  }
}

 

Step 3: Modify sdk version in global.json

dotnet --info

D:\developer_mini_core\src\Miniblog.Core>dotnet --info

Host (useful for support):
  Version: 6.0.0-rc.2.21480.5
  Commit:  6b11d64e7e

.NET SDKs installed:
  5.0.301 [C:\Program Files\dotnet\sdk]
// here is sdk version: 6.0.100-rc.2.21505.57
  6.0.100-rc.2.21505.57 [C:\Program Files\dotnet\sdk]       

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.2.21501.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

step 4:  Use Global usings (in C# 10 and later)

create a file, for example: GlobalUsings.cs.Add them into the GlobalUsings.cs file with adding the global keyword for each:

Add GlobalUsings.cs

path:D:\developer_mini_core\src\Miniblog.Core\GlobalUsings.cs

global using System.Runtime.CompilerServices;

global using Miniblog.Core;
global using Miniblog.Core.Services;

global using IWmmLogger = WebMarkupMin.Core.Loggers.ILogger;
global using MetaWeblogService = Miniblog.Core.Services.MetaWeblogService;
global using WmmNullLogger = WebMarkupMin.Core.Loggers.NullLogger;

global using WilderMinds.MetaWeblog;

other:

default global usings to Microsoft.NET.Sdk.Web

global using global::System;
global using global::System.Collections.Generic;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Net.Http.Json;
global using global::System.Threading.Tasks;
global using global::Microsoft.AspNetCore.Builder;
global using global::Microsoft.AspNetCore.Hosting;
global using global::Microsoft.AspNetCore.Http;
global using global::Microsoft.AspNetCore.Mvc;
global using global::Microsoft.AspNetCore.Routing;
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging; 

 

Add default global usings to Microsoft.NET.Sdk.Web #32451

 

step 5:Add custom services to the container.

path:D:\developer_mini_core\src\Miniblog.Core\Program.cs

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();


builder.Services.AddSingleton<IUserServices, BlogUserServices>();
builder.Services.AddSingleton<IBlogService, FileBlogService>();
builder.Services.Configure<BlogSettings>(this.Configuration.GetSection("blog"));
builder.Services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddMetaWeblog<MetaWeblogService>();

step 6: change default port from 5215 to port 5000 in file launchSettings.json D:\developer_mini_core\src\Miniblog.Core\Properties\launchSettings.json

-"applicationUrl": "http://localhost:5215",
+"applicationUrl": "http://localhost:5000",

Web字体

选择正确的字体对于为博客的读者提供良好的体验至关重要。通常这意味着使用CSS加载和使用的自定义Web字体。自定义Web字体的问题是浏览器需要下载它们,并且在慢速移动连接上可能需要一段时间。

相反,我想使用内置于各种浏览器的字体来提供相同的高质量阅读体验,但没有额外的文件下载。这是我使用的CSS:

 

body { font: 19px/1.6 "Open Sans", Ubuntu, "Nimbus Sans L", Avenir, AvenirNext, "Segoe UI", Helvetica, Arial, sans-serif;}

上述字体系列可确保在任何给定的浏览器/操作系统或设备上安装至少一种字体。

图像优化

多年来,我一直在使用Visual Studio 的Image Optimizer扩展来优化我的Web项目中的图像。这对于我之前所知的图片来说非常棒,但是作为博客文章的一部分,用户上传的图片又如何呢?在上传时,需要在生产服务器上优化图像。

据我所知,没有.NET Core库可以优化图像以及Image Optimizer扩展,因此我创建了一个Azure Webjob,其中包含与扩展完全相同的优化算法并将其包装在NuGet包中。

它被称为Azure Image Optimizer,可以将其添加到任何ASP.NET项目中 - 无需额外的步骤。当ASP.NET应用程序发布到Azure时,NuGet包将向发布输出添加Webjob,该输出会在到达Azure后自动启动并监视图像文件。它不会在您的项目中留下任何工件,也不需要任何代码更改 - 只需添加NuGet包并部署到Azure。

内容分发网络(CDN)

为了确保尽可能优化博客,我决定让它非常容易利用CDN来提供所有静态文件,如JavaScript,CSS和图像。

为此,我使用WebEssentials.AspNetCore.CdnTagHelpers Nuget包,通过将其添加到appsettings.json来自动CDNify所有静态资源引用:

{ “cdn”:{ “url”:“https://myname.azureedge.net” }}

Sass,捆绑和缩小

1.可选方案

All Tools for bundling and minification in ASP.NET Core

2.技术选型

我想使用Sass而不是普通的旧CSS,所以我需要一种方法来编译它。我可以设置Gulp或WebPack来处理JavaScript和Sass的转换,缩小和捆绑,但我决定采用更简单的方法,即LigerShark WebOptimizer.Core和LigerShark.WebOptimizer.Sass NuGet包。

通过使用这些包,我得到运行时和/或构建时资产管道管理,几乎没有代码。唯一需要的是在Startup.cs中注册服务和中间件,如下所示:

 services.AddWebOptimizer(pipeline => 
            { 
                pipeline.MinifyJsFiles();
                pipeline.CompileScssFiles()
                .InlineImages();
            });

这将自动编译和缩小我的Sass文件到CSS并缩小JavaScript文件。无需其他代码或工件。我非常喜欢将WebOptimizer管道用于不需要Gulp或WebPack的网站。

 

Modify Owner

 "owner": "By Mads Kristensen",

Miniblog.Core-master\src\appsettings.json

{
  "forcessl": false,
  "user": {
    "username": "demo8",
    // Generate a new password hash with salt here https://onlinehasher.azurewebsites.net/
    "password": "EB53D045EB132825A39F59AEA3FC453F216CB088775D6E7CE4A9740611B573CD", // this password is "dem88o"
    "salt": "any custom string"
  },
  "webOptimizer": {
    "enableCaching": true
  },
  "blog": {
    "commentsCloseAfterDays": 10,
    "owner": "By Mads Kristensen",  //here
    "listView": "TitlesAndExcerpts",
    "postsPerPage": 4
  },
  "cdn": {
    "url": ""
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Information"
    }
  }
}

 

 

 

error

dotnet run
crit: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to start Kestrel.
      System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
      To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.

s

# dotnet dev-certs https --trust
Trusting the HTTPS development certificate was requested. Trusting the certificate on Linux distributions automatically is not supported. For instructions on how to manually trust the certificate on your Linux distribution, go to https://aka.ms/dev-certs-trust

run ok

Useful links

how Elasticsearch works with ASP.NET Core Mads Kristensen's MiniBlog.Core

https://miroslavpopovic.com/posts/2018/07/elasticsearch-with-aspnet-core-and-docker

 

Blog engine for ASP.NET Core 6.x by madskristensen

github 地址:https://github.com/madskristensen/Miniblog.Core

Mini Blog Blogger template - BTemplates

https://btemplates.com/2013/blogger-template-mini-blog/

 

Other open-source blogs project on github.com

Blogifier

Blogifier is an open-source publishing platform Written in .NET 5.0 and Blazor WebAssembly

https://github.com/blogifierdotnet/Blogifier

 

Blog.Core

Blog.Core 开箱即用的企业级前后端分离【 .NET Core5.0 Api + Vue 2.x + RBAC】权限框架

https://github.com/anjoy8/Blog.Core