Skip to content

Commit f6830ec

Browse files
Add initial template
1 parent c93fd4d commit f6830ec

File tree

83 files changed

+74421
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+74421
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
################################################################################
2+
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3+
################################################################################
4+
5+
/.vs
6+
/obj
7+
/bin

Controllers/HomeController.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace StaticBlogTemplate.Controllers;
4+
5+
public class HomeController : Controller
6+
{
7+
public IActionResult Index()
8+
{
9+
return View();
10+
}
11+
12+
public IActionResult Privacy()
13+
{
14+
return View();
15+
}
16+
public IActionResult Blog()
17+
{
18+
return View();
19+
}
20+
}

Controllers/PostsController.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace StaticBlogTemplate.Controllers;
4+
5+
public class PostsController : Controller
6+
{
7+
public IActionResult WelcomeToMyBlog()
8+
{
9+
return View();
10+
}
11+
}

Models/ErrorViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace StaticBlogTemplate.Models;
2+
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}

Posts/WelcomeToMyBlog.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Introduction
2+
3+
Hi, this is my **new** blog!
4+
5+
I write it using the *awesome* [Markdown](https://en.wikipedia.org/wiki/Markdown) language!
6+
7+
I can also render images automatically, as long as they are in the wwwroot folder:
8+
9+
![Markdown logo](/images/Markdown-mark.svg.png)
10+
11+
Same with using the standard `img` HTML tag:
12+
13+
<img src="/images/Markdown-mark.svg.png" alt="Markdown logo" width="50%"/>
14+
15+
Bootstrap classes are also rendered:
16+
17+
<div class="alert alert-info">
18+
I also support Bootstrap classes.
19+
</div>

Program.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
var mvcBuilder = builder.Services.AddControllersWithViews();
5+
6+
#if DEBUG
7+
mvcBuilder.AddRazorRuntimeCompilation();
8+
#endif
9+
10+
var app = builder.Build();
11+
12+
app.UseStaticFiles();
13+
14+
app.UseRouting();
15+
16+
app.MapControllerRoute(
17+
name: "default",
18+
pattern: "{controller=Home}/{action=Index}/{id?}");
19+
20+
app.Run();

Properties/launchSettings.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:25132",
7+
"sslPort": 44336
8+
}
9+
},
10+
"profiles": {
11+
"StaticBlogTemplate": {
12+
"commandName": "Project",
13+
"dotnetRunMessages": true,
14+
"launchBrowser": true,
15+
"applicationUrl": "https://localhost:7112;http://localhost:5112",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"IIS Express": {
21+
"commandName": "IISExpress",
22+
"launchBrowser": true,
23+
"environmentVariables": {
24+
"ASPNETCORE_ENVIRONMENT": "Development"
25+
}
26+
}
27+
}
28+
}

StaticBlogTemplate.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Markdig" Version="0.30.3" />
11+
<PackageReference Include="Markdown.ColorCode" Version="1.0.1" />
12+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.8" Condition="'$(Configuration)' =='Debug'" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<Folder Include="wwwroot\images\" />
17+
</ItemGroup>
18+
19+
</Project>

StaticBlogTemplate.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32811.315
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StaticBlogTemplate", "StaticBlogTemplate.csproj", "{EBC32921-1F05-4E9C-AD2A-D0DC51C69F51}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{EBC32921-1F05-4E9C-AD2A-D0DC51C69F51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EBC32921-1F05-4E9C-AD2A-D0DC51C69F51}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EBC32921-1F05-4E9C-AD2A-D0DC51C69F51}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EBC32921-1F05-4E9C-AD2A-D0DC51C69F51}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {7C48FAB6-0572-4730-AF3F-CF0568447D98}
24+
EndGlobalSection
25+
EndGlobal

Views/Home/Blog.cshtml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@{
2+
ViewData["Title"] = "Blog";
3+
}
4+
5+
<div class="text-center">
6+
<h1 class="display-4">Welcome to my blog</h1>
7+
</div>
8+
9+
<div>
10+
<ul>
11+
<li>
12+
<a asp-controller="Posts" asp-action="WelcomeToMyBlog">Welcome To My Blog!</a>
13+
</li>
14+
</ul>
15+
</div>

Views/Home/Index.cshtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
<div class="text-center">
6+
<h1 class="display-4">Welcome</h1>
7+
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
8+
</div>

Views/Home/Privacy.cshtml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h1>@ViewData["Title"]</h1>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>

Views/Posts/WelcomeToMyBlog.cshtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
ViewData["Title"] = "Welcome to my blog!";
3+
}

Views/Posts/_PostLayout.cshtml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@using Markdig;
2+
@using Microsoft.AspNetCore.Hosting;
3+
4+
@inject IWebHostEnvironment environment;
5+
6+
@{
7+
Layout = "_Layout";
8+
9+
// This assumes the name of the View/Markdown file is the same name as that of the Action in the Controller.
10+
// If you want to use another structure, you can add a property to the ViewBag/ViewData.
11+
string post = ViewContext.RouteData.Values["action"] + ".md";
12+
var file = System.IO.File.ReadAllText(System.IO.Path.Combine(environment.ContentRootPath, "Posts", post));
13+
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().UseBootstrap().Build();
14+
var renderedMarkdown = Markdig.Markdown.ToHtml(file, pipeline);
15+
IgnoreBody();
16+
}
17+
18+
<h1>@ViewData["Title"]</h1>
19+
20+
<div class="blog-post-wrapper">
21+
@Html.Raw(renderedMarkdown)
22+
</div>

Views/Posts/_ViewStart.cshtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "_PostLayout";
3+
}

Views/Shared/Error.cshtml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@model ErrorViewModel
2+
@{
3+
ViewData["Title"] = "Error";
4+
}
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (Model.ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>

Views/Shared/_Layout.cshtml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - StaticBlogTemplate</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
</head>
10+
<body>
11+
<header>
12+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
13+
<div class="container-fluid">
14+
<a class="navbar-brand" asp-controller="Home" asp-action="Index">StaticBlogTemplate</a>
15+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
16+
aria-expanded="false" aria-label="Toggle navigation">
17+
<span class="navbar-toggler-icon"></span>
18+
</button>
19+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
20+
<ul class="navbar-nav flex-grow-1">
21+
<li class="nav-item">
22+
<a class="nav-link text-dark" asp-controller="Home" asp-action="Index">Home</a>
23+
</li>
24+
<li class="nav-item">
25+
<a class="nav-link text-dark" asp-controller="Home" asp-action="Privacy">Privacy</a>
26+
</li>
27+
<li class="nav-item">
28+
<a class="nav-link text-dark" asp-controller="Home" asp-action="Blog">Blog</a>
29+
</li>
30+
</ul>
31+
</div>
32+
</div>
33+
</nav>
34+
</header>
35+
<div class="container">
36+
<main role="main" class="pb-3">
37+
@RenderBody()
38+
</main>
39+
</div>
40+
41+
<footer class="border-top footer text-muted">
42+
<div class="container">
43+
&copy; 2022 - StaticBlogTemplate - <a asp-controller="Home" asp-action="Privacy">Privacy</a>
44+
</div>
45+
</footer>
46+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
47+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
48+
<script src="~/js/site.js" asp-append-version="true"></script>
49+
@await RenderSectionAsync("Scripts", required: false)
50+
</body>
51+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
2+
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>

Views/_ViewImports.cshtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@using StaticBlogTemplate
2+
@using StaticBlogTemplate.Models
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

Views/_ViewStart.cshtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "_Layout";
3+
}

appsettings.Development.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}

appsettings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}

0 commit comments

Comments
 (0)