forked from cory/tildefriends
		
	Fiddling with blog links.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4749 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "type": "tildefriends-app",
 | 
					  "type": "tildefriends-app",
 | 
				
			||||||
  "emoji": "🪵",
 | 
					  "emoji": "🪵",
 | 
				
			||||||
  "previous": "&7E+OhgnyEUUIIHPhvWCF6esqRRDdqPHhqJiGp1h6xg4=.sha256"
 | 
					  "previous": "&7Ch5DjIMAEbJm05ofH1U/+wlzn9kr65DChcKKgurE8E=.sha256"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -8,7 +8,7 @@ function escapeAttribute(text) {
 | 
				
			|||||||
	return (text ?? '').replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''');
 | 
						return (text ?? '').replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function markdown(md) {
 | 
					export function markdown(md) {
 | 
				
			||||||
	let reader = new commonmark.Parser({safe: true});
 | 
						let reader = new commonmark.Parser({safe: true});
 | 
				
			||||||
	let writer = new commonmark.HtmlRenderer();
 | 
						let writer = new commonmark.HtmlRenderer();
 | 
				
			||||||
	let parsed = reader.parse(md || '');
 | 
						let parsed = reader.parse(md || '');
 | 
				
			||||||
@@ -17,10 +17,10 @@ function markdown(md) {
 | 
				
			|||||||
	while ((event = walker.next())) {
 | 
						while ((event = walker.next())) {
 | 
				
			||||||
		node = event.node;
 | 
							node = event.node;
 | 
				
			||||||
		if (event.entering) {
 | 
							if (event.entering) {
 | 
				
			||||||
			if (node.type == 'image') {
 | 
								if (node.destination?.startsWith('&')) {
 | 
				
			||||||
				if (node.destination.startsWith('&')) {
 | 
									node.destination = '/' + node.destination + '/view?filename=' + node.firstChild?.literal;
 | 
				
			||||||
					node.destination = '/' + node.destination + '/view';
 | 
								} else if (node.destination?.startsWith('@') || node.destination?.startsWith('%')) {
 | 
				
			||||||
				}
 | 
									node.destination = '/~core/ssb/#' + node.destination;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -31,6 +31,9 @@ export async function render_blog_post_html(blog_post) {
 | 
				
			|||||||
	let blob = utf8Decode(await ssb.blobGet(blog_post.blog));
 | 
						let blob = utf8Decode(await ssb.blobGet(blog_post.blog));
 | 
				
			||||||
	return `<!DOCTYPE html>
 | 
						return `<!DOCTYPE html>
 | 
				
			||||||
		<html>
 | 
							<html>
 | 
				
			||||||
 | 
								<head>
 | 
				
			||||||
 | 
									<base target="_top">
 | 
				
			||||||
 | 
								</head>
 | 
				
			||||||
			<body>
 | 
								<body>
 | 
				
			||||||
				<div>
 | 
									<div>
 | 
				
			||||||
					<div><a href="../ssb/#${escapeAttribute(blog_post.author)}">${escape(blog_post.name)}</a> ${escape(new Date(blog_post.timestamp).toString())}</div>
 | 
										<div><a href="../ssb/#${escapeAttribute(blog_post.author)}">${escape(blog_post.name)}</a> ${escape(new Date(blog_post.timestamp).toString())}</div>
 | 
				
			||||||
@@ -44,7 +47,7 @@ export async function render_blog_post_html(blog_post) {
 | 
				
			|||||||
function render_blog_post(blog_post) {
 | 
					function render_blog_post(blog_post) {
 | 
				
			||||||
	return `
 | 
						return `
 | 
				
			||||||
		<div>
 | 
							<div>
 | 
				
			||||||
			<h2><a href="../ssb/#${escapeAttribute(blog_post.id)}">${escape(blog_post.title)}</a></h2>
 | 
								<h2><a href="./${escapeAttribute(blog_post.id)}">${escape(blog_post.title)}</a></h2>
 | 
				
			||||||
			<div><a href="../ssb/#${escapeAttribute(blog_post.author)}">${escape(blog_post.name)}</a> ${escape(new Date(blog_post.timestamp).toString())}</div>
 | 
								<div><a href="../ssb/#${escapeAttribute(blog_post.author)}">${escape(blog_post.name)}</a> ${escape(new Date(blog_post.timestamp).toString())}</div>
 | 
				
			||||||
			<div>${markdown(blog_post.summary)}</div>
 | 
								<div>${markdown(blog_post.summary)}</div>
 | 
				
			||||||
		</div>
 | 
							</div>
 | 
				
			||||||
@@ -62,11 +65,11 @@ export function render_html(blogs) {
 | 
				
			|||||||
						background-color: #ccc;
 | 
											background-color: #ccc;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				</style>
 | 
									</style>
 | 
				
			||||||
				<base target="_blank">
 | 
									<base target="_top">
 | 
				
			||||||
			</head>
 | 
								</head>
 | 
				
			||||||
			<body>
 | 
								<body>
 | 
				
			||||||
				<div style="display: flex; flex-direction: row; align-items: center; gap: 1em">
 | 
									<div style="display: flex; flex-direction: row; align-items: center; gap: 1em">
 | 
				
			||||||
					<h1>🪵Tilde Blog</h1>
 | 
										<h1>🪵Tilde Friends Blog</h1>
 | 
				
			||||||
					<div style="font-size: xx-small; vertical-align: middle"><a href="/~cory/blog/atom">atom feed</a></div>
 | 
										<div style="font-size: xx-small; vertical-align: middle"><a href="/~cory/blog/atom">atom feed</a></div>
 | 
				
			||||||
				</div>
 | 
									</div>
 | 
				
			||||||
				${blogs.map(blog_post => render_blog_post(blog_post)).join('\n')}
 | 
									${blogs.map(blog_post => render_blog_post(blog_post)).join('\n')}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,17 +1,39 @@
 | 
				
			|||||||
import * as blog from './blog.js';
 | 
					import * as blog from './blog.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function main() {
 | 
					async function main() {
 | 
				
			||||||
	let blogs = await blog.get_posts();
 | 
						if (request.path.startsWith('%') && request.path.endsWith('.sha256')) {
 | 
				
			||||||
	for (let blog_post of blogs) {
 | 
							let id = request.path.startsWith('%25') ? '%' + request.path.substring(3) : request.path;
 | 
				
			||||||
		let title = (blog_post.title || '').replaceAll(/\W/g, '_').toLowerCase();
 | 
							let blob = await ssb.messageContentGet(id);
 | 
				
			||||||
		if (request.path === title) {
 | 
							if (blob) {
 | 
				
			||||||
			respond({data: await blog.render_blog_post_html(blog_post), content_type: 'text/html; charset=utf-8'});
 | 
								let content = JSON.parse(utf8Decode(blob));
 | 
				
			||||||
			return;
 | 
								let md = content?.text;
 | 
				
			||||||
 | 
								if (content?.type == 'blog') {
 | 
				
			||||||
 | 
									md = utf8Decode(await ssb.blobGet(content?.blog));
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								respond({data: `<!DOCTYPE html>
 | 
				
			||||||
 | 
								<html>
 | 
				
			||||||
 | 
									<head>
 | 
				
			||||||
 | 
										<base target="_top">
 | 
				
			||||||
 | 
									</head>
 | 
				
			||||||
 | 
									<body>
 | 
				
			||||||
 | 
										${blog.markdown(md)}
 | 
				
			||||||
 | 
									</body>
 | 
				
			||||||
 | 
								</html>`, content_type: 'text/html; charset=utf-8'});
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								respond({data: `Message ${id} not found.`, content_type: 'text/html; charset=utf-8'});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						} else if (request.path == 'atom') {
 | 
				
			||||||
	if (request.path == 'atom') {
 | 
							let blogs = await blog.get_posts();
 | 
				
			||||||
		respond({data: blog.render_atom(blogs), content_type: 'application/atom+xml'});
 | 
							respond({data: blog.render_atom(blogs), content_type: 'application/atom+xml'});
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
 | 
							let blogs = await blog.get_posts();
 | 
				
			||||||
 | 
							for (let blog_post of blogs) {
 | 
				
			||||||
 | 
								let title = (blog_post.title || '').replaceAll(/\W/g, '_').toLowerCase();
 | 
				
			||||||
 | 
								if (request.path === title) {
 | 
				
			||||||
 | 
									respond({data: await blog.render_blog_post_html(blog_post), content_type: 'text/html; charset=utf-8'});
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		respond({data: blog.render_html(blogs), content_type: 'text/html; charset=utf-8'});
 | 
							respond({data: blog.render_html(blogs), content_type: 'text/html; charset=utf-8'});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user