Skip to content

Commit

Permalink
Try adding article html content to rss.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Drewery committed Jun 29, 2023
1 parent bb4b116 commit b307c0a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
9 changes: 8 additions & 1 deletion rss/generate-rss.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const RSS = require('rss');
const axios = require('axios');

// Read index.json
const index = JSON.parse(fs.readFileSync('content/index.json', 'utf8'));
Expand All @@ -19,13 +20,19 @@ const feed = new RSS({
// Loop over the articles in the index and add them to the feed
for (const articleId in index) {
const article = index[articleId];

const response = await axios.get("blog.drewery.uk/raw/" + articleId);

feed.item({
title: article.title,
description: 'You can add a description here',
url: `https://yourwebsite.com/${articleId}`, // URL of the article
date: article.date,

// Add the article content as HTML
content: response.data
});
}

// Write the XML to a file
fs.writeFileSync('rss.xml', feed.xml());
fs.writeFileSync('rss.xml', feed.xml());
5 changes: 3 additions & 2 deletions rss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"rss": "^1.2.2"
"rss": "^1.2.2",
"axios": "^0.21.1"
}
}
}
39 changes: 39 additions & 0 deletions site/Pages/Raw.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@layout EmptyLayout
@inject HttpClient Http
@inject IJSRuntime JsRuntime
@page "/raw/{Id}"
@using Markdig

@code {
[Parameter]
public string? Id { get; set; }

string? _content;

protected override async Task OnParametersSetAsync()
{
var markdown = await Http.GetStringAsync($"https://raw.githubusercontent.com/adam-drewery/blog/main/content/{Id}.md")
?? throw new InvalidOperationException("Failed to get blog content");

_content = Markdown.ToHtml(markdown);
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
await JsRuntime.InvokeVoidAsync("fitImages");
await JsRuntime.InvokeVoidAsync("highlightCode");
}
}

<div class="page-wrapper">
<section class="pb-5">
<div class="container">
<div class="row pt-5">
<div class="col-xl-8">
@if (_content != null) { @((MarkupString)_content) }
</div>
<div id="comments" class="col-xl-8"></div>
</div>
</div>
</section>
</div>
2 changes: 2 additions & 0 deletions site/Shared/EmptyLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@inherits LayoutComponentBase
@Body

0 comments on commit b307c0a

Please sign in to comment.