Emdash source with visual editor image upload fix
Fixes: 1. media.ts: wrap placeholder generation in try-catch 2. toolbar.ts: check r.ok, display error message in popover
This commit is contained in:
26
packages/core/tests/unit/templates/blog-reading-time.test.ts
Normal file
26
packages/core/tests/unit/templates/blog-reading-time.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { getReadingTime } from "../../../../../templates/blog/src/utils/reading-time";
|
||||
|
||||
function makeContent(text: string) {
|
||||
return [
|
||||
{
|
||||
_type: "block",
|
||||
children: [{ _type: "span", text }],
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
describe("blog template reading time", () => {
|
||||
it("keeps word-based reading time for English content", () => {
|
||||
expect(getReadingTime(makeContent("word ".repeat(200)))).toBe(1);
|
||||
});
|
||||
|
||||
it("counts CJK content by character length", () => {
|
||||
expect(getReadingTime(makeContent("日".repeat(2000)))).toBe(4);
|
||||
});
|
||||
|
||||
it("adds English words and CJK characters for mixed-language posts", () => {
|
||||
expect(getReadingTime(makeContent(`${"word ".repeat(100)}${"日".repeat(500)}`))).toBe(2);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { resolveBlogSiteIdentity as resolveBlogSiteIdentityCloudflare } from "../../../../../templates/blog-cloudflare/src/utils/site-identity";
|
||||
import { resolveBlogSiteIdentity as resolveBlogSiteIdentityNode } from "../../../../../templates/blog/src/utils/site-identity";
|
||||
|
||||
describe("blog template site identity", () => {
|
||||
it("uses CMS site title and tagline when provided", () => {
|
||||
// Favicon is intentionally absent from the helper return: core's
|
||||
// EmDashHead now emits the favicon link via renderSiteIdentity()
|
||||
// (#831), so the template no longer needs to surface it.
|
||||
const settings = {
|
||||
title: "Example Site",
|
||||
tagline: "Writing about shipping software",
|
||||
logo: { mediaId: "logo-1", alt: "My Logo", url: "/_emdash/api/media/file/logo.webp" },
|
||||
favicon: { mediaId: "fav-1", url: "/_emdash/api/media/file/favicon.svg" },
|
||||
};
|
||||
|
||||
expect(resolveBlogSiteIdentityNode(settings)).toEqual({
|
||||
siteTitle: "Example Site",
|
||||
siteTagline: "Writing about shipping software",
|
||||
siteLogo: { mediaId: "logo-1", alt: "My Logo", url: "/_emdash/api/media/file/logo.webp" },
|
||||
});
|
||||
expect(resolveBlogSiteIdentityCloudflare(settings)).toEqual({
|
||||
siteTitle: "Example Site",
|
||||
siteTagline: "Writing about shipping software",
|
||||
siteLogo: { mediaId: "logo-1", alt: "My Logo", url: "/_emdash/api/media/file/logo.webp" },
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to the bundled blog defaults when settings are missing", () => {
|
||||
expect(resolveBlogSiteIdentityNode({})).toEqual({
|
||||
siteTitle: "My Blog",
|
||||
siteTagline: "Thoughts, stories, and ideas.",
|
||||
siteLogo: null,
|
||||
});
|
||||
expect(resolveBlogSiteIdentityCloudflare({})).toEqual({
|
||||
siteTitle: "My Blog",
|
||||
siteTagline: "Thoughts, stories, and ideas.",
|
||||
siteLogo: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves intentionally blank settings instead of restoring defaults", () => {
|
||||
const settings = {
|
||||
title: "Example Site",
|
||||
tagline: "",
|
||||
siteLogo: "",
|
||||
};
|
||||
|
||||
expect(resolveBlogSiteIdentityNode(settings)).toEqual({
|
||||
siteTitle: "Example Site",
|
||||
siteTagline: "",
|
||||
siteLogo: null,
|
||||
});
|
||||
expect(resolveBlogSiteIdentityCloudflare(settings)).toEqual({
|
||||
siteTitle: "Example Site",
|
||||
siteTagline: "",
|
||||
siteLogo: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null for logo without resolved URL", () => {
|
||||
const settings = {
|
||||
title: "Example Site",
|
||||
tagline: "",
|
||||
logo: { mediaId: "logo-1" },
|
||||
};
|
||||
|
||||
expect(resolveBlogSiteIdentityNode(settings)).toEqual({
|
||||
siteTitle: "Example Site",
|
||||
siteTagline: "",
|
||||
siteLogo: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { resolveStarterSiteIdentity as resolveStarterSiteIdentityCloudflare } from "../../../../../templates/starter-cloudflare/src/utils/site-identity";
|
||||
import { resolveStarterSiteIdentity as resolveStarterSiteIdentityNode } from "../../../../../templates/starter/src/utils/site-identity";
|
||||
|
||||
describe("starter template site identity", () => {
|
||||
it("uses CMS site title and tagline when provided", () => {
|
||||
// Favicon is intentionally absent from the helper return: core's
|
||||
// EmDashHead now emits the favicon link via renderSiteIdentity()
|
||||
// (#831), so the template no longer needs to surface it.
|
||||
const settings = {
|
||||
title: "Example Site",
|
||||
tagline: "Shipping notes",
|
||||
logo: { mediaId: "logo-1", alt: "My Logo", url: "/_emdash/api/media/file/logo.webp" },
|
||||
favicon: { mediaId: "fav-1", url: "/_emdash/api/media/file/favicon.svg" },
|
||||
};
|
||||
|
||||
expect(resolveStarterSiteIdentityNode(settings)).toEqual({
|
||||
siteTitle: "Example Site",
|
||||
siteTagline: "Shipping notes",
|
||||
siteLogo: { mediaId: "logo-1", alt: "My Logo", url: "/_emdash/api/media/file/logo.webp" },
|
||||
});
|
||||
expect(resolveStarterSiteIdentityCloudflare(settings)).toEqual({
|
||||
siteTitle: "Example Site",
|
||||
siteTagline: "Shipping notes",
|
||||
siteLogo: { mediaId: "logo-1", alt: "My Logo", url: "/_emdash/api/media/file/logo.webp" },
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to starter defaults when settings are missing", () => {
|
||||
expect(resolveStarterSiteIdentityNode({})).toEqual({
|
||||
siteTitle: "My Site",
|
||||
siteTagline: "Built with EmDash",
|
||||
siteLogo: null,
|
||||
});
|
||||
expect(resolveStarterSiteIdentityCloudflare({})).toEqual({
|
||||
siteTitle: "My Site",
|
||||
siteTagline: "Built with EmDash",
|
||||
siteLogo: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null for logo without resolved URL", () => {
|
||||
const settings = {
|
||||
title: "Example Site",
|
||||
tagline: "",
|
||||
logo: { mediaId: "logo-1" },
|
||||
};
|
||||
|
||||
expect(resolveStarterSiteIdentityNode(settings)).toEqual({
|
||||
siteTitle: "Example Site",
|
||||
siteTagline: "",
|
||||
siteLogo: null,
|
||||
});
|
||||
expect(resolveStarterSiteIdentityCloudflare(settings)).toEqual({
|
||||
siteTitle: "Example Site",
|
||||
siteTagline: "",
|
||||
siteLogo: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user