1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00

Chore: Fix website build (#11359)

This commit is contained in:
Henry Heino 2024-11-09 04:44:12 -08:00 committed by GitHub
parent 4a88d6ff7a
commit 3894c05217
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 2 deletions

View File

@ -1537,6 +1537,7 @@ packages/tools/update-readme-download.test.js
packages/tools/update-readme-download.js packages/tools/update-readme-download.js
packages/tools/update-readme-sponsors.js packages/tools/update-readme-sponsors.js
packages/tools/updateMarkdownDoc.js packages/tools/updateMarkdownDoc.js
packages/tools/utils/discourse.test.js
packages/tools/utils/discourse.js packages/tools/utils/discourse.js
packages/tools/utils/loadSponsors.js packages/tools/utils/loadSponsors.js
packages/tools/utils/translation.js packages/tools/utils/translation.js

1
.gitignore vendored
View File

@ -1514,6 +1514,7 @@ packages/tools/update-readme-download.test.js
packages/tools/update-readme-download.js packages/tools/update-readme-download.js
packages/tools/update-readme-sponsors.js packages/tools/update-readme-sponsors.js
packages/tools/updateMarkdownDoc.js packages/tools/updateMarkdownDoc.js
packages/tools/utils/discourse.test.js
packages/tools/utils/discourse.js packages/tools/utils/discourse.js
packages/tools/utils/loadSponsors.js packages/tools/utils/loadSponsors.js
packages/tools/utils/translation.js packages/tools/utils/translation.js

View File

@ -1,7 +1,7 @@
import { pathExists } from 'fs-extra'; import { pathExists } from 'fs-extra';
import { readFile, writeFile } from 'fs/promises'; import { readFile, writeFile } from 'fs/promises';
import { GitHubRelease, gitHubLatestReleases, gitHubLinkify } from './tool-utils'; import { GitHubRelease, gitHubLatestReleases, gitHubLinkify } from './tool-utils';
import { config, createPost, createTopic, getForumTopPostByExternalId, getTopicByExternalId, updatePost } from './utils/discourse'; import { config, createPost, createTopic, getForumTopPostByExternalId, getTopicByExternalId, trimPostToMaximumLength, updatePost } from './utils/discourse';
import { compareVersions } from 'compare-versions'; import { compareVersions } from 'compare-versions';
import dayjs = require('dayjs'); import dayjs = require('dayjs');
import { getRootDir } from '@joplin/utils'; import { getRootDir } from '@joplin/utils';
@ -135,7 +135,11 @@ const processReleases = async (releases: GitHubRelease[], platform: Platform, st
await updatePost(topPost.id, { await updatePost(topPost.id, {
title: topicTitle, title: topicTitle,
raw: `${topPost.raw}\n\n${postBody}`, // With a large number of pre-releases, the top post can get very long
// and needs to be trimmed.
raw: trimPostToMaximumLength(
`${topPost.raw}\n\n${postBody}`,
),
edit_reason: 'Auto-updated by script', edit_reason: 'Auto-updated by script',
}); });

View File

@ -0,0 +1,18 @@
import { trimPostToMaximumLength } from './discourse';
describe('utils/discourse', () => {
it('trimPostToMaximumLength should allow trimming posts to a maximum length', () => {
const makeLongString = (length: number) => {
const resultParts = [];
while (resultParts.length < length) {
resultParts.push('1');
}
return resultParts.join('');
};
const longContent = makeLongString(70_000);
const trimmed = trimPostToMaximumLength(longContent);
expect(trimmed.length).toBeLessThan(65_000);
expect(trimmed).toContain(`${longContent.substring(0, 65_000 - 153)}...\n\n**Note**:`);
});
});

View File

@ -1,3 +1,4 @@
import { substrWithEllipsis } from '@joplin/lib/string-utils';
import { msleep } from '@joplin/utils/time'; import { msleep } from '@joplin/utils/time';
import fetch from 'node-fetch'; import fetch from 'node-fetch';
@ -141,3 +142,16 @@ export const createPost = async (topicId: number, post: any): Promise<ForumTopic
export const updatePost = async (postId: number, content: any): Promise<void> => { export const updatePost = async (postId: number, content: any): Promise<void> => {
await execApi(HttpMethod.PUT, `posts/${postId}.json`, content); await execApi(HttpMethod.PUT, `posts/${postId}.json`, content);
}; };
export const trimPostToMaximumLength = (postBody: string) => {
// Discourse has a maximum post length of 65_000:
const maximumLength = 65_000;
if (postBody.length > maximumLength) {
return [
substrWithEllipsis(postBody, 0, maximumLength - 150),
'**Note**: The full content of this post is longer than permitted by Discourse.',
].join('\n\n');
}
return postBody;
};