function processSection()

in website/src/plugins/changelog/index.js [26:85]


function processSection(section) {
  const title = section
    .match(/\n## .*/)?.[0]
    .trim()
    .replace('## ', '');
  if (!title) {
    return null;
  }
  const content = section
    .replace(/\n## .*/, '')
    .trim()
    .replace('running_woman', 'running');

  let authors = content.match(/## Committers: \d.*/s);
  if (authors) {
    authors = authors[0]
      .match(/- .*/g)
      .map(
        (line) =>
          line.match(
            /- (?:(?<name>.*?) \()?\[@(?<alias>.*)\]\((?<url>.*?)\)\)?/,
          ).groups,
      )
      .map((author) => ({
        ...author,
        name: author.name ?? author.alias,
        imageURL: `https://github.com/${author.alias}.png`,
      }))
      .sort((a, b) => a.url.localeCompare(b.url));

    authors.forEach((author) => {
      authorsMap[author.alias] = author;
    });
  }
  let hour = 20;
  const date = title.match(/ \((?<date>.*)\)/)?.groups.date;
  while (publishTimes.has(`${date}T${hour}:00`)) {
    hour -= 1;
  }
  publishTimes.add(`${date}T${hour}:00`);

  return {
    title: title.replace(/ \(.*\)/, ''),
    content: `---
date: ${`${date}T${hour}:00`}${
      authors
        ? `
authors:
${authors.map((author) => `  - '${author.alias}'`).join('\n')}`
        : ''
    }
---

# ${title.replace(/ \(.*\)/, '')}

<!-- truncate -->

${content.replace(/####/g, '##')}`,
  };
}