V2 #1

Merged
danieljsummers merged 102 commits from v2 into main 2022-06-23 00:35:12 +00:00
3 changed files with 106 additions and 4 deletions
Showing only changes of commit 92cc50254c - Show all commits

View File

@ -11,6 +11,8 @@ open Microsoft.AspNetCore.Http
open MyWebLog open MyWebLog
open MyWebLog.ViewModels open MyWebLog.ViewModels
// ~~ FEED GENERATION ~~
/// The type of feed to generate /// The type of feed to generate
type FeedType = type FeedType =
| StandardFeed | StandardFeed
@ -211,12 +213,11 @@ let private addPodcast webLog (rssFeed : SyndicationFeed) (feed : CustomFeed) =
rssFeed.ElementExtensions.Add ("category", "itunes", categoryXml) rssFeed.ElementExtensions.Add ("category", "itunes", categoryXml)
rssFeed.ElementExtensions.Add ("explicit", "itunes", ExplicitRating.toString podcast.explicit) rssFeed.ElementExtensions.Add ("explicit", "itunes", ExplicitRating.toString podcast.explicit)
rssFeed.ElementExtensions.Add ("subscribe", "rawvoice", feedUrl) rssFeed.ElementExtensions.Add ("subscribe", "rawvoice", feedUrl)
// GET {any-prescribed-feed} /// Create a feed with a known non-zero-length list of posts
let generate (feedType : FeedType) postCount : HttpHandler = fun next ctx -> backgroundTask { let createFeed (feedType : FeedType) posts : HttpHandler = fun next ctx -> backgroundTask {
let webLog = ctx.WebLog let webLog = ctx.WebLog
let conn = ctx.Conn let conn = ctx.Conn
let! posts = getFeedPosts webLog feedType postCount conn
let! authors = Post.getAuthors webLog posts conn let! authors = Post.getAuthors webLog posts conn
let! tagMaps = Post.getTagMappings webLog posts conn let! tagMaps = Post.getTagMappings webLog posts conn
let cats = CategoryCache.get ctx let cats = CategoryCache.get ctx
@ -255,3 +256,24 @@ let generate (feedType : FeedType) postCount : HttpHandler = fun next ctx -> bac
return! (setHttpHeader "Content-Type" "text/xml" >=> setStatusCode 200 >=> setBodyFromString output) next ctx return! (setHttpHeader "Content-Type" "text/xml" >=> setStatusCode 200 >=> setBodyFromString output) next ctx
} }
// GET {any-prescribed-feed}
let generate (feedType : FeedType) postCount : HttpHandler = fun next ctx -> backgroundTask {
match! getFeedPosts ctx.WebLog feedType postCount ctx.Conn with
| posts when List.length posts > 0 -> return! createFeed feedType posts next ctx
| _ -> return! Error.notFound next ctx
}
// ~~ FEED ADMINISTRATION ~~
open DotLiquid
// GET: /admin/rss/settings
let editSettings : HttpHandler = fun next ctx -> task {
// TODO: stopped here
return!
Hash.FromAnonymousObject
{| csrf = csrfToken ctx
|}
|> viewForTheme "admin" "rss-settings" next ctx
}

View File

@ -93,6 +93,9 @@ let router : HttpHandler = choose [
routef "/%s/edit" Post.edit routef "/%s/edit" Post.edit
routef "/%s/permalinks" Post.editPermalinks routef "/%s/permalinks" Post.editPermalinks
]) ])
subRoute "/rss" (choose [
route "/settings" >=> Feed.editSettings
])
route "/settings" >=> Admin.settings route "/settings" >=> Admin.settings
subRoute "/tag-mapping" (choose [ subRoute "/tag-mapping" (choose [
route "s" >=> Admin.tagMappings route "s" >=> Admin.tagMappings

View File

@ -0,0 +1,77 @@
<h2 class="my-3">{{ web_log.name }} RSS Options</h2>
<article>
<form action="{{ "admin/rss/settings" | relative_link }}" method="post">
<input type="hidden" name="{{ csrf.form_field_name }}" value="{{ csrf.request_token }}">
<div class="container">
<div class="row">
<div class="col-12 col-md-6 col-xl-4 offset-xl-1 pb-3">
<div class="form-check form-switch pb-2">
<input type="checkbox" name="feedEnabled" id="feedEnabled" class="form-check-input" value="true"
{% if model.feed_enabled %}checked="checked"{% endif %}>
<label for="feedEnabled" class="form-check-label">Main Feed Enabled</label>
</div>
</div>
<div class="col-12 col-md-6 col-xl-4 pb-3">
<div class="form-floating">
<input type="text" name="feedName" id="feedName" class="form-control" value="{{ model.feed_name }}">
<label for="feedName">Feed File Name</label>
<span class="form-text">Default is <code>feed.xml</code></span>
</div>
</div>
<div class="col-12 col-md-4 col-xl-2 pb-3">
<div class="form-floating">
<input type="number" name="itemsInFeed" id="itemsInFeed" class="form-control" min="0" required
value="{{ model.items_in_feed }}">
<label for="itemsInFeed">Items in Feed</label>
<span class="form-text">Set to &ldquo;0&rdquo; to use &ldquo;Posts per Page&rdquo; setting</span>
</div>
</div>
<div class="col-12 col-md-4 col-xl-3 offset-xl-1 pb-3">
<div class="form-check form-switch pb-2">
<input type="checkbox" name="categoryEnabled" id="categoryEnabled" class="form-check-input" value="true"
{% if model.category_enabled %}checked="checked"{% endif %}>
<label for="categoryEnabled" class="form-check-label">Enable Category Feed</label>
</div>
<div class="form-check form-switch pb-2">
<input type="checkbox" name="tagEnabled" id="tagEnabled" class="form-check-input" value="true"
{% if model.tag_enabled %}checked="checked"{% endif %}>
<label for="tagEnabled" class="form-check-label">Enable Tag Feed</label>
</div>
</div>
</div>
<div class="row pb-3">
<div class="col text-center">
<button type="submit" class="btn btn-primary">Save Changes</button>
</div>
</div>
</div>
</form>
<h3>Custom Feeds</h3>
<a class="btn btn-secondary" href="{{ 'admin/rss/new/edit' | relative_link }}">Add a New Custom Feed</a>
{%- assign feed_count = model.custom_feeds | size -%}
{% if feed_count > 0 %}
<table class="table table-sm table-striped table-hover">
<thead>
<tr>
<th scope="col">Source</th>
<th scope="col">Path</th>
<th scope="col">Podcast?</th>
</tr>
</thead>
<tbody>
{% for feed in model.custom_feeds %}
<tr>
<td>
{{ feed.source }}
<!-- TODO: edit / delete -->
</td>
<td>{{ feed.path }}</td>
<td>{% if feed.is_podcast %}Yes{% else %}No{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="text-muted fst-italic">No custom feeds defined</p>
{% endif %}
</article>