Skip to content

Commit

Permalink
Markdown fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Galloway committed Jul 31, 2024
1 parent d1a9ae6 commit 59bcd0a
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 287 deletions.
2 changes: 1 addition & 1 deletion Mostlylucid/Controllers/BlogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public class BlogController(BlogService blogService, ILogger<BlogController> log
public IActionResult Show(string slug)
{
var post = blogService.GetPost(slug);
return View();
return View("Post", post);
}
}
10 changes: 6 additions & 4 deletions Mostlylucid/Markdown/githubactions.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Using GitHub Actions to build and push a docker image

<!--category-- Docker, GitHub Actions -->


This is a simple example of how to use GitHub Actions to build and push a docker image to a container registry.


## Prerequisites

- A docker file exists for the project you want to build and push.
Expand All @@ -14,7 +13,9 @@ This is a simple example of how to use GitHub Actions to build and push a docker

For this project I started with the basic .NET Core ASP.NET project and the default Dockerfile created by Rider.


### Dockerfile

This Dockerfile is a multi-stage build that builds the project and then copies the output to a runtime image.

For this proect, as I use TailwindCSS, I also need to install Node.js and run the TailwindCSS build command.
Expand All @@ -32,7 +33,6 @@ This downloads the latest (at the time of writing) version of Node.js and instal

Later in the file

<details>

```dockerfile

Expand Down Expand Up @@ -81,4 +81,6 @@ ENTRYPOINT ["dotnet", "Mostlylucid.dll"]

### Full DockerFile

</details>


<!--category-- Docker, GitHub Actions -->
11 changes: 11 additions & 0 deletions Mostlylucid/Models/Blog/BlogPostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ public class BlogPostViewModel

public string Slug { get; set; }= string.Empty;

public string ReadingTime
{
get
{
var readCount = (float)WordCount / 200;
return readCount <1 ? "Less than a minute" : $"{Math.Round(readCount)} minute read";
}
}

public int WordCount { get; set; }

public DateTime UpdatedDate { get; set; }

public DateTime CreatedDate { get; set; }
Expand Down
45 changes: 32 additions & 13 deletions Mostlylucid/Services/BlogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Mostlylucid.Services;

public class BlogService(ILogger<BlogService> logger)
{
private MarkdownPipeline pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
private const string Path = "Markdown";

public BlogPostViewModel? GetPost(string postName)
Expand All @@ -16,8 +17,8 @@ public class BlogService(ILogger<BlogService> logger)
var page = GetPage(path, true);
return new BlogPostViewModel
{
Categories = page.categories, Content = page.text, UpdatedDate = page.lastWrite,
CreatedDate = page.created, Slug = page.slug, Title = page.title
Categories = page.categories,WordCount = WordCount(page.restOfTheLines) , Content = page.processed, UpdatedDate = page.lastWriteTime,
CreatedDate = page.creationTime, Slug = page.slug, Title = page.title
};
}
catch (Exception e)
Expand Down Expand Up @@ -54,21 +55,39 @@ private static string[] GetCategories(string markdownText)
.ToArray();
return categories;
}

public (string title, string slug, DateTime created, DateTime lastWrite, string text, string[] categories, string
restOfTheLines) GetPage(string page, bool html)

public (string title, string slug, DateTime creationTime, DateTime lastWriteTime, string processed, string[] categories, string restOfTheLines) GetPage(string page, bool html)
{
var fileInfo = new FileInfo(page);
var lines = System.IO.File.ReadAllLines(page);
var title = Markdown.ToPlainText(lines[0].Trim());

// Ensure the file exists
if (!fileInfo.Exists)
{
throw new FileNotFoundException("The specified file does not exist.", page);
}

var restOfTheLines = string.Concat(lines.Skip(1));
// Read all lines from the file
var lines = System.IO.File.ReadAllLines(page);

// Get the title from the first line
var title = lines.Length > 0 ? Markdown.ToPlainText(lines[0].Trim()) : string.Empty;

// Concatenate the rest of the lines with newline characters
var restOfTheLines = string.Join(Environment.NewLine, lines.Skip(1));

// Extract categories from the text
var categories = GetCategories(restOfTheLines);

// Remove category tags from the text
restOfTheLines = CategoryRegex.Replace(restOfTheLines, "");
var processed = html ? Markdown.ToHtml(restOfTheLines) : Markdown.ToPlainText(restOfTheLines);



// Process the rest of the lines as either HTML or plain text
var processed = html ? Markdown.ToHtml(restOfTheLines, pipeline) : Markdown.ToPlainText(restOfTheLines, pipeline);

// Generate the slug from the page filename
var slug = GetSlug(page);

// Return the parsed and processed content
return (title, slug, fileInfo.CreationTime, fileInfo.LastWriteTime, processed, categories, restOfTheLines);
}

Expand All @@ -84,8 +103,8 @@ public List<PostListModel> GetPosts()
pageModels.Add(new PostListModel
{
Categories = pageInfo.categories, Title = pageInfo.title,
Slug = pageInfo.slug, WordCount = WordCount(pageInfo.restOfTheLines), UpdatedDate = pageInfo.lastWrite,
CreatedDate = pageInfo.created, Summary = summary
Slug = pageInfo.slug, WordCount = WordCount(pageInfo.restOfTheLines), UpdatedDate = pageInfo.lastWriteTime,
CreatedDate = pageInfo.creationTime, Summary = summary
});
}

Expand Down
92 changes: 14 additions & 78 deletions Mostlylucid/Views/Blog/Post.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

@model Mostlylucid.Models.Blog.BlogPostViewModel

@{
ViewBag.Title = "title";
Expand All @@ -7,93 +7,30 @@

<div class="pt-16 lg:pt-20">
<div class="border-b border-grey-lighter pb-8 sm:pb-12">
<span
class="mb-5 inline-block rounded-full bg-green-light px-2 py-1 font-body text-sm text-green sm:mb-8"
>category</span
>
@foreach(var category in Model.Categories)
{
<span class="mb-5 inline-block rounded-full bg-green-light px-2 py-1 font-body text-sm text-green sm:mb-8">@category</span>
}
<h2
class="block font-body text-3xl font-semibold leading-tight text-primary dark:text-white sm:text-4xl md:text-5xl"
>
Using Git Submodules for Private Content
class="block font-body text-3xl font-semibold leading-tight text-primary dark:text-white sm:text-4xl md:text-5xl">
@Model.Title
</h2>
<div class="flex items-center pt-5 sm:pt-8">
<p class="pr-2 font-body font-light text-primary dark:text-white">
July 19, 2020
@Model.CreatedDate.ToString("D")
</p>
<span class="vdark:text-white font-body text-grey">//</span>
<p class="pl-2 font-body font-light text-primary dark:text-white">
4 min read
@Model.ReadingTime
</p>
</div>
</div>
<div
class="prose prose max-w-none border-b border-grey-lighter py-8 dark:prose-dark sm:py-12"
>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Augue ut lectus arcu bibendum at varius vel pharetra vel. Turpis nunc eget lorem dolor sed viverra ipsum nunc aliquet. Massa placerat duis ultricies lacus sed turpis tincidunt. Cursus sit amet dictum sit amet justo donec enim. Nec dui nunc mattis enim ut tellus elementum sagittis vitae. Id semper risus in hendrerit gravida rutrum quisque. Posuere ac ut consequat semper viverra nam libero justo laoreet. Turpis cursus in hac habitasse platea.</p>

<p>Elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. Pellentesque massa placerat duis ultricies lacus sed. Interdum velit laoreet id donec ultrices tincidunt arcu non. Id diam maecenas ultricies mi eget mauris. Urna id volutpat lacus laoreet non. Amet est placerat in egestas erat imperdiet sed euismod. Dui sapien eget mi proin sed libero enim sed faucibus. Facilisis mauris sit amet massa vitae. Vitae congue mauris rhoncus aenean vel elit. Ut etiam sit amet nisl. Commodo odio aenean sed adipiscing diam donec adipiscing tristique.</p>

<p>Non odio euismod lacinia at quis risus. Elit duis tristique sollicitudin nibh sit amet commodo. Aliquam ultrices sagittis orci a scelerisque purus semper eget duis. Ipsum consequat nisl vel pretium lectus. Pretium vulputate sapien nec sagittis aliquam. Morbi tincidunt augue interdum velit euismod in pellentesque massa. Nullam non nisi est sit.</p>

<blockquote>
<p>Note: Some of the earlier articles may be amateur and have information that I wouldn’t necessarily put into an article on the subject if I wrote it today.</p>
</blockquote>

<h3 id="lorem-ipsum-dolor-sit-amet">Lorem ipsum dolor sit amet</h3>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Amet aliquam id diam maecenas ultricies mi eget mauris pharetra. Congue nisi vitae suscipit tellus.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua:</p>

<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</li>
</ul>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Risus viverra adipiscing at in tellus. Proin libero nunc consequat interdum. Sed arcu non odio euismod lacinia at quis.</p>

<div class="twitter-card">
<h4 class="twitter-card-title"> "When gone am I, the last of the Jedi will you be. The Force runs strong in your family. Pass on what you have learned."</h4>
<span class="twitter-card-source">— Episode 6, Return of the Jedi</span>
<button class="twitter-card-btn">Share this on Twitter</button>
</div>

<p>It’s great that I learned all that, because for my first real job in the industry, I was going to use practically none of it. No Git, no Node, no Sass, no Grunt nor Gulp, no command line, no Bootstrap. Just cold, hard WordPress. Nonetheless, this was going to present a and things to learn.&lt;/p&gt;</p>

<h3 id="sed-do-eiusmod-tempor-incididunt">Sed do eiusmod tempor incididunt</h3>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Enim lobortis scelerisque fermentum dui faucibus in ornare quam viverra. Augue ut lectus arcu bibendum at varius vel. Lacus viverra vitae congue eu consequat ac felis.</p>

<p><img src="/assets/img/post-image-01.png" alt="Image" /></p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Condimentum id venenatis a condimentum vitae sapien pellentesque habitant morbi. Semper feugiat nibh sed pulvinar.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel pretium lectus quam id leo in. Ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue eget.</p>

<h3 id="ullamcorper-dignissim-cras-tincidunt">Ullamcorper dignissim cras tincidunt</h3>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Laoreet non curabitur gravida arcu ac tortor dignissim convallis aenean. Integer enim neque volutpat ac tincidunt vitae semper quis lectus.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, <a href="/">sed do eiusmod tempor incididunt ut</a> labore et dolore magna aliqua. Leo a diam sollicitudin tempor id eu nisl nunc.</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">btn</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="dl">'</span><span class="s1">btn</span><span class="dl">'</span><span class="p">)</span>
<span class="kd">let</span> <span class="nx">count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="kd">function</span> <span class="nx">render</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">btn</span><span class="p">.</span><span class="nx">innerText</span> <span class="o">=</span> <span class="s2">`Count: </span><span class="p">${</span><span class="nx">count</span><span class="p">}</span><span class="s2">`</span>
<span class="p">}</span>
<span class="nx">btn</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="dl">'</span><span class="s1">click</span><span class="dl">'</span><span class="p">,</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="p">{</span>
<span class="c1">// Count from 1 to 10.</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">count</span> <span class="o">&lt;</span> <span class="mi">10</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="nx">render</span><span class="p">()</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
class="prose prose max-w-none border-b border-grey-lighter py-8 dark:prose-dark sm:py-12">
@Html.Raw(Model.Content)
</div>


</div>

<div class="flex items-center py-10">
Expand All @@ -120,5 +57,4 @@
class="bx bxl-reddit pl-2 text-2xl text-primary transition-colors hover:text-secondary dark:text-white dark:hover:text-secondary"
></i
></a>
</div>
</div>
</div>
3 changes: 1 addition & 2 deletions Mostlylucid/Views/Shared/_ListPost.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<span
class="mb-4 inline-block rounded-full bg-green-light px-2 py-1 font-body text-sm text-green">@category</span>
}
<a
asp-action="Show" asp-route-slug="@Model.Slug" asp-controller="Blog"
<a asp-action="Show" asp-route-slug="@Model.Slug" asp-controller="Blog"
class="block font-body text-lg font-semibold text-primary transition-colors hover:text-green dark:text-white dark:hover:text-secondary">@Model.Title</a>
<div class="block font-body">@Model.Summary</div>
<div class="flex items-center pt-4">
Expand Down
4 changes: 1 addition & 3 deletions Mostlylucid/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,9 @@
},
},
plugins: [
require("@tailwindcss/typography")({
modifiers: [],
}),
require("@tailwindcss/forms"),
require("@tailwindcss/aspect-ratio"),
require("@tailwindcss/typography"),
require('daisyui'),
],
};
Loading

0 comments on commit 59bcd0a

Please sign in to comment.