Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 20 additions & 25 deletions lib/routes/microsoft/message-center.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const route: Route = {
url: 'mc.merill.net',
categories: ['program-update'],
example: '/microsoft/message-center',
description: 'Microsoft 365 Message Center archive entries from mc.merill.net.',
description:
'Microsoft 365 Message Center archive entries from mc.merill.net. The item guid carries the last modification time, so an updated post appears as a new item. The bare message ID (e.g. MC1234567) is in the author field.',
features: {
requireConfig: false,
requirePuppeteer: false,
Expand All @@ -73,13 +74,12 @@ async function handler(ctx) {
const { data: messages }: { data: MessageCenterMessage[] } = await got(dataUrl);

if (!Array.isArray(messages)) {
throw new Error('Failed to fetch Microsoft 365 Message Center archive data.');
throw new TypeError('Failed to fetch Microsoft 365 Message Center archive data.');
}

const item = messages
.filter(isMessageCenterMessage)
.slice()
.sort((a, b) => getTimestamp(b) - getTimestamp(a))
.filter((message) => isMessageCenterMessage(message))
.toSorted((a, b) => getTimestamp(b) - getTimestamp(a))
.slice(0, pageSize)
.map((message): DataItem => {
const link = `${rootUrl}/message/${message.Id}`;
Expand All @@ -93,7 +93,8 @@ async function handler(ctx) {
return {
title: message.Title,
link,
guid: message.Id,
guid: getVersionedGuid(message),
author: message.Id,
description,
pubDate,
updated,
Expand All @@ -113,30 +114,29 @@ async function handler(ctx) {
};
}

function getVersionedGuid(message: MessageCenterMessage) {
const version = message.LastModifiedDateTime || message.StartDateTime;

return version ? `${message.Id}@${version}` : message.Id;
}

function getTimestamp(message: MessageCenterMessage) {
const date = message.LastModifiedDateTime || message.StartDateTime;

return date ? Date.parse(date) || 0 : 0;
}

function getCategories(message: MessageCenterMessage, messageCenterCategory?: string) {
const categories = [
messageCenterCategory,
message.Severity,
...(message.Services ?? []),
...(message.Tags ?? []),
].filter((category): category is string => Boolean(category));
const categories = [messageCenterCategory, message.Severity, ...(message.Services ?? []), ...(message.Tags ?? [])].filter((category): category is string => !!category);

return categories.length ? [...new Set(categories)] : undefined;
}

function getContent(description: string, messageCenterCategory?: string, severity?: string, endDate?: Date) {
const endDateValue = endDate && !Number.isNaN(endDate.getTime()) ? endDate.toISOString() : undefined;
const metadata = [
messageCenterCategory ? `MessageCenterCategory: ${messageCenterCategory}` : undefined,
severity ? `Severity: ${severity}` : undefined,
endDateValue ? `EndDateTime: ${endDateValue}` : undefined,
].filter((value): value is string => Boolean(value));
const metadata = [messageCenterCategory ? `MessageCenterCategory: ${messageCenterCategory}` : undefined, severity ? `Severity: ${severity}` : undefined, endDateValue ? `EndDateTime: ${endDateValue}` : undefined].filter(
(value): value is string => !!value
);

if (!metadata.length) {
return {
Expand All @@ -159,7 +159,7 @@ function getDetailValue(message: MessageCenterMessage, name: string) {
}

function getMessageCenterCategory(category?: string) {
return category ? categoryLabels[category] ?? category : undefined;
return category ? (categoryLabels[category] ?? category) : undefined;
}

function getImages(description: string) {
Expand Down Expand Up @@ -229,7 +229,7 @@ function getAbsoluteUrl(url: string) {
try {
return new URL(url, rootUrl).href;
} catch {
return undefined;
return;
}
}

Expand Down Expand Up @@ -260,10 +260,5 @@ function isRoadmapTitle(title: string) {
}

function escapeHtml(value: string) {
return value
.replaceAll('&', '&')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
.replaceAll("'", '&#39;');
return value.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#39;');
}
Loading