Files snapshot from mithril-server-side-rendering

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
a8328f Tucker McKnight
a8328f Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
a8328f Tucker McKnight
14e3d3 Tucker McKnight
14e3d3 Tucker McKnight
import m from 'mithril'
import render from 'mithril-node-render'
import _ from 'lodash'
import { type Repository } from '../src/dataTypes.ts'
import branches from '../src/branches.ts'
import { dateToRfc3339 } from '@11ty/eleventy-plugin-rss'
import flatPatches from '../src/flatPatches.ts'

export default async (
  eleventyConfig: any,
) => {
  return (data) => {
    const branch: ReturnType<typeof branches>[0] = data.branch
    const currentRepo: Repository = data.currentRepo
    const currentBranch: Repository['branches'][0] = data.currentBranch
    const currentBranchCommits: Awaited<ReturnType<typeof flatPatches>> = data.currentBranchCommits

    const slugify = eleventyConfig.getFilter("slugify")

    return render([
      m.trust('<?xml version="1.0" encoding="utf-8"?>'),
      m('feed', {xmlns: "http://www.w3.org/2005/Atom"}, [
        m('title', `Latest patches in ${branch.branchName}`),
        m.trust(`<link href="${ data.reposConfig.baseUrl + '/repos/' + slugify(branch.repoName) + '/branches/' + slugify(branch.branchName) + '/commits.xml'}" rel="self" />`),
        m.trust(`<link href="${data.reposConfig.baseUrl + '/repos/' + slugify(branch.repoName) + '/branches/' + slugify(branch.branchName)}" />`),
        m('updated', dateToRfc3339(currentRepo.commits.get(currentBranch.head).date)),
        m('id', data.reposConfig.baseUrl),
        m('author',
          m('name', `${_.escape(currentRepo.name)} contributors`)
        ),
        currentBranchCommits.map((commit) => {
          const commitUrl = data.reposConfig.baseUrl + '/repos/' + slugify(branch.repoName) + '/branches/' + slugify(branch.branchName) + '/commits/' + commit.commit.hash
          return m('entry', [
            m('title', _.escape(commit.commit.message.split('\n')[0])),
            m('author', m('name', _.escape(commit.commit.author))),
            m.trust(`<link href="${commitUrl}" />`),
            m('updated', dateToRfc3339(commit.commit.date)),
            m('id', commitUrl),
            m('content', {type: "text"}, _.escape(commit.commit.message)),
          ])
        })
      ])
    ])
  }
}