zenn-model 0.1.158 → 0.1.159-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +2 -0
- package/lib/types.d.ts +1 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +14 -0
- package/package.json +3 -2
package/lib/index.js
CHANGED
|
@@ -40,6 +40,7 @@ function getValidationErrors(item, validators) {
|
|
|
40
40
|
}
|
|
41
41
|
const validateArticle = (article) => {
|
|
42
42
|
const validators = [
|
|
43
|
+
import_utils.validateBody,
|
|
43
44
|
import_utils.validateItemSlug,
|
|
44
45
|
import_utils.validateMissingTitle,
|
|
45
46
|
import_utils.validateTitleLength,
|
|
@@ -60,6 +61,7 @@ const validateArticle = (article) => {
|
|
|
60
61
|
};
|
|
61
62
|
const validateBook = (book) => {
|
|
62
63
|
const validators = [
|
|
64
|
+
import_utils.validateBody,
|
|
63
65
|
import_utils.validateItemSlug,
|
|
64
66
|
import_utils.validateMissingTitle,
|
|
65
67
|
import_utils.validateTitleLength,
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type Dect = Record<string, any>;
|
|
2
|
-
export type ValidationErrorType = 'item-slug' | 'missing-title' | 'title-length' | 'published-status' | 'published-at-parse' | 'published-at-schedule' | 'article-type' | 'missing-emoji' | 'emoji-format' | 'missing-topics' | 'too-many-topics' | 'topic-type' | 'invalid-topic-letters' | 'use-tags' | 'publication-name' | 'book-summary' | 'book-price-type' | 'book-price-range' | 'book-price-fraction' | 'missing-book-cover' | 'book-cover-size' | 'book-cover-aspect-ratio' | 'book-chapter-slugs' | 'book-chapters-format' | 'chapter-item-slug' | 'chapter-free-type';
|
|
2
|
+
export type ValidationErrorType = 'body' | 'item-slug' | 'missing-title' | 'title-length' | 'published-status' | 'published-at-parse' | 'published-at-schedule' | 'article-type' | 'missing-emoji' | 'emoji-format' | 'missing-topics' | 'too-many-topics' | 'topic-type' | 'invalid-topic-letters' | 'use-tags' | 'publication-name' | 'book-summary' | 'book-price-type' | 'book-price-range' | 'book-price-fraction' | 'missing-book-cover' | 'book-cover-size' | 'book-cover-aspect-ratio' | 'book-chapter-slugs' | 'book-chapters-format' | 'chapter-item-slug' | 'chapter-free-type';
|
|
3
3
|
export type ItemValidator = {
|
|
4
4
|
type: ValidationErrorType;
|
|
5
5
|
isCritical?: boolean;
|
package/lib/utils.d.ts
CHANGED
|
@@ -30,3 +30,4 @@ export declare const validateBookChapterSlugs: ItemValidator;
|
|
|
30
30
|
export declare const validateBookChaptersFormat: ItemValidator;
|
|
31
31
|
export declare const validateChapterItemSlug: ItemValidator;
|
|
32
32
|
export declare const validateChapterFreeType: ItemValidator;
|
|
33
|
+
export declare const validateBody: ItemValidator;
|
package/lib/utils.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(utils_exports, {
|
|
|
31
31
|
PUBLISHED_AT_PATTERN: () => PUBLISHED_AT_PATTERN,
|
|
32
32
|
isAnyText: () => isAnyText,
|
|
33
33
|
validateArticleType: () => validateArticleType,
|
|
34
|
+
validateBody: () => validateBody,
|
|
34
35
|
validateBookChapterSlugs: () => validateBookChapterSlugs,
|
|
35
36
|
validateBookChaptersFormat: () => validateBookChaptersFormat,
|
|
36
37
|
validateBookCoverAspectRatio: () => validateBookCoverAspectRatio,
|
|
@@ -61,6 +62,7 @@ __export(utils_exports, {
|
|
|
61
62
|
});
|
|
62
63
|
module.exports = __toCommonJS(utils_exports);
|
|
63
64
|
var import_emoji_regex = __toESM(require("emoji-regex"));
|
|
65
|
+
var cheerio = __toESM(require("cheerio"));
|
|
64
66
|
function validateSlug(slug) {
|
|
65
67
|
if (!slug)
|
|
66
68
|
return false;
|
|
@@ -330,3 +332,15 @@ const validateChapterFreeType = {
|
|
|
330
332
|
getMessage: () => "free\uFF08\u7121\u6599\u516C\u958B\u8A2D\u5B9A\uFF09\u306B\u306F true \u3082\u3057\u304F\u306F false\u306E\u307F\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044",
|
|
331
333
|
isValid: ({ free }) => free === void 0 || typeof free === "boolean"
|
|
332
334
|
};
|
|
335
|
+
const validateBody = {
|
|
336
|
+
type: "body",
|
|
337
|
+
isCritical: true,
|
|
338
|
+
getMessage: () => `\u8A18\u4E8B\u672C\u6587\u306B\u30A8\u30E9\u30FC\u304C\u3042\u308A\u307E\u3059\u3002\u672C\u6587\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`,
|
|
339
|
+
// data-body-error がある場合はエラー
|
|
340
|
+
isValid: ({ bodyHtml }) => {
|
|
341
|
+
if (!bodyHtml)
|
|
342
|
+
return true;
|
|
343
|
+
const $ = cheerio.load(bodyHtml);
|
|
344
|
+
return !$("[data-body-error]").length;
|
|
345
|
+
}
|
|
346
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zenn-model",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.159-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Model utils for Zenn contents",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"vitest": "^0.34.4"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"cheerio": "^1.0.0-rc.12",
|
|
38
39
|
"emoji-regex": "^10.2.1"
|
|
39
40
|
},
|
|
40
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "efb1f00e38e2b86dfac079278aadf1b9d227ec87"
|
|
41
42
|
}
|