feat: truncate short description exceeding the byte limit (#143)
Some checks failed
Publish Docker Image / publish (push) Has been cancelled

* feat: truncate short description exceeding the byte limit

* fix tests
This commit is contained in:
Peter Evans
2023-04-07 09:16:46 +09:00
committed by GitHub
parent 3ba533f0ff
commit 4b1a4bb484
7 changed files with 80 additions and 47 deletions

View File

@@ -1,6 +1,6 @@
import * as core from '@actions/core'
import * as fs from 'fs'
import unicodeSubstring = require('unicode-substring')
import * as utils from './utils'
export const README_FILEPATH_DEFAULT = './README.md'
export const IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp'
@@ -28,14 +28,6 @@ type Rule = {
absUrlPrefix: string
}
export function truncateToBytes(s: string, n: number): string {
let len = n
while (Buffer.byteLength(s) > n) {
s = unicodeSubstring(s, 0, len--)
}
return s
}
export async function getReadmeContent(
readmeFilepath: string,
enableUrlCompletion: boolean,
@@ -53,7 +45,7 @@ export async function getReadmeContent(
imageExtensions
)
const truncatedReadmeContent = truncateToBytes(readmeContent, MAX_BYTES)
const truncatedReadmeContent = utils.truncateToBytes(readmeContent, MAX_BYTES)
if (truncatedReadmeContent.length !== readmeContent.length) {
core.warning(
`The README content exceeds DockerHub's limit and has been truncated to ${MAX_BYTES} bytes.`