Add data management, randomized HTML drip and public README

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-11-14 16:08:45 +01:00
1 parent 3671019e60
commit f5d8ca7484
46 files changed
+1601 -172

No files matched your search

+170
View File
@@ -0,0 +1,170 @@
using System.Text;
using Flypaper.Core.Abstractions;
namespace Flypaper.Core.Strategies;
public static class HtmlContent
{
private const string Css = """
body { margin: 0 auto; max-width: 52rem; padding: 1.5rem; font: 16px/1.6 system-ui, sans-serif; color: #222; }
header { border-bottom: 1px solid #ddd; margin-bottom: 1.5rem; }
nav a { margin-right: 1rem; color: #0b5cad; text-decoration: none; }
h1, h2, h3 { line-height: 1.25; }
article { margin-bottom: 2rem; }
a { color: #0b5cad; }
""";
private static readonly string[] Vocabulary =
[
"lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit", "sed", "do", "eiusmod",
"tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua", "enim", "ad", "minim",
"veniam", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "aliquip", "ex", "ea",
"commodo", "consequat", "duis", "aute", "irure", "in", "reprehenderit", "voluptate", "velit", "esse",
"cillum", "fugiat", "nulla", "pariatur", "excepteur", "sint", "occaecat", "cupidatat", "non", "proident",
"sunt", "culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum", "praesent",
"luctus", "vitae", "semper", "facilisis", "integer", "nec", "odio", "mauris", "massa", "vestibulum",
"lacinia", "arcu", "eget", "nunc", "tristique", "fermentum", "pellentesque", "habitant", "morbi",
"senectus", "netus", "malesuada", "fames", "turpis", "egestas", "porttitor", "rhoncus", "dapibus",
"ornare", "sapien", "volutpat", "blandit", "aliquam", "etiam", "erat", "velit", "scelerisque",
"viverra", "orci", "sagittis", "eu", "tellus", "cras", "pulvinar", "mattis", "pharetra", "convallis",
"posuere", "morbi", "leo", "urna", "molestie", "at", "elementum", "sodales", "neque", "gravida",
"dictum", "fusce", "ultrices", "placerat", "euismod", "quam", "suspendisse", "potenti", "nullam",
"accumsan", "tincidunt", "varius", "sollicitudin", "imperdiet", "hendrerit", "bibendum", "cursus"
];
private static readonly string[] Sections =
["docs", "blog", "wiki", "support", "products", "archive", "news", "help", "files", "guides", "kb", "releases"];
private static readonly string[] Titles =
["Welcome", "Documentation", "Knowledge Base", "Support Center", "Release Notes", "Resources", "Archive", "Developer Portal"];
public static IEnumerable<string> Generate(IRandomSource random)
{
var title = $"{Pick(random, Titles)} · {Title(random, 2, 3)}";
yield return $"""
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{title}</title>
<style>
{Css}
</style>
</head>
<body>
<header>
<h1>{title}</h1>
""";
yield return Navigation(random);
yield return "</header>\n<main>\n";
while (true)
{
yield return random.Next(0, 10) switch
{
< 5 => Article(random),
< 7 => LinkList(random),
< 9 => Paragraph(random),
_ => $"<h3>{Title(random, 2, 6)}</h3>\n{Paragraph(random)}"
};
}
}
private static string Navigation(IRandomSource random)
{
var builder = new StringBuilder("<nav>\n");
var count = random.Next(3, 7);
for (var i = 0; i < count; i++)
{
builder.Append($"<a href=\"/{Pick(random, Sections)}/\">{Capitalize(Pick(random, Vocabulary))}</a>\n");
}
return builder.Append("</nav>\n").ToString();
}
private static string Article(IRandomSource random)
{
var builder = new StringBuilder($"<article>\n<h2>{Title(random, 3, 9)}</h2>\n");
var paragraphs = random.Next(1, 6);
for (var i = 0; i < paragraphs; i++)
{
builder.Append(Paragraph(random));
}
return builder.Append("</article>\n").ToString();
}
private static string LinkList(IRandomSource random)
{
var ordered = random.Next(0, 2) == 0;
var builder = new StringBuilder(ordered ? "<ol>\n" : "<ul>\n");
var items = random.Next(3, 10);
for (var i = 0; i < items; i++)
{
builder.Append($"<li>{Link(random, random.Next(2, 6))}</li>\n");
}
return builder.Append(ordered ? "</ol>\n" : "</ul>\n").ToString();
}
private static string Paragraph(IRandomSource random)
{
var builder = new StringBuilder("<p>");
var sentences = random.Next(2, 9);
for (var i = 0; i < sentences; i++)
{
if (i > 0)
{
builder.Append(' ');
}
builder.Append(Sentence(random));
}
return builder.Append("</p>\n").ToString();
}
private static string Sentence(IRandomSource random)
{
var builder = new StringBuilder();
var words = random.Next(4, 21);
var linkAt = random.Next(0, 8) == 0 ? random.Next(1, words) : -1;
for (var i = 0; i < words; i++)
{
if (i > 0)
{
builder.Append(i > 2 && random.Next(0, 9) == 0 ? ", " : " ");
}
if (i == linkAt)
{
builder.Append(Link(random, random.Next(1, 4)));
continue;
}
var word = Pick(random, Vocabulary);
builder.Append(i == 0 ? Capitalize(word) : word);
}
return builder.Append(random.Next(0, 10) == 0 ? '?' : '.').ToString();
}
private static string Link(IRandomSource random, int words)
{
var text = Phrase(random, words);
var slug = text.Replace(' ', '-');
return $"<a href=\"/{Pick(random, Sections)}/{slug}\">{text}</a>";
}
private static string Title(IRandomSource random, int min, int max) => Capitalize(Phrase(random, random.Next(min, max + 1)));
private static string Phrase(IRandomSource random, int count) =>
string.Join(' ', Enumerable.Range(0, count).Select(_ => Pick(random, Vocabulary)));
private static string Pick(IRandomSource random, string[] values) => values[random.Next(0, values.Length)];
private static string Capitalize(string value) => value.Length == 0 ? value : char.ToUpperInvariant(value[0]) + value[1..];
}