iT邦幫忙

0

請教 TypeScript 的問題

  • 分享至 

  • xImage

小弟剛學 TypeScript,請問為什麼會出現以下錯誤

generate-rss.ts

import { escape } from "@/lib/utils/htmlEscaper";
import siteMetadata from "@/data/siteMetadata";
import { PostFrontMatter } from "@/lib/types";

interface Props {
  post: PostFrontMatter;
  locale: string;
  defaultLocale: string;
}

const generateRssItem = ({ post, locale, defaultLocale }: Props) => {
  return `
  <item>
    <guid>${siteMetadata.siteUrl}${defaultLocale === locale ? "" : "/" + locale}/blog/${
    post.slug
  }</guid>
    <title>${escape(post.title)}</title>
    <link>${siteMetadata.siteUrl}${defaultLocale === locale ? "" : "/" + locale}/blog/${
    post.slug
  }</link>
    ${post.summary && `<description>${escape(post.summary)}</description>`}
    <pubDate>${new Date(post.date).toLocaleDateString(locale)}</pubDate>
    <author>${siteMetadata.email} (${siteMetadata.author})</author>
    ${post.tags && post.tags.map((t) => `<category>${t}</category>`).join("")}
  </item>
`;
};

interface RSSProps {
  posts: PostFrontMatter[];
  locale: string;
  defaultLocale: string;
  page?: string;
}

const generateRss = ({ posts, locale, defaultLocale, page = "feed.xml" }: RSSProps) => {
  `
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>${escape(siteMetadata.title)}</title>
    <link>${siteMetadata.siteUrl}${defaultLocale === locale ? "" : "/" + locale}/blog</link>
    <description>${escape(siteMetadata.description[locale])}</description>
    <language>${locale}</language>
    <managingEditor>${siteMetadata.email} (${siteMetadata.author})</managingEditor>
    <webMaster>${siteMetadata.email} (${siteMetadata.author})</webMaster>
    <lastBuildDate>${new Date(posts[0].date).toLocaleDateString(locale)}</lastBuildDate>
    <atom:link href="${siteMetadata.siteUrl}/${page.replace(
    ".xml",
    defaultLocale === locale ? ".xml" : "." + locale + ".xml",
  )}" rel="self" type="application/rss+xml"/>
    ${posts.map((post) => generateRssItem(post, locale, defaultLocale)).join("")}
  </channel>
</rss>
`;
};
export default generateRss;

https://i.imgur.com/f1PZU38.png

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

3
galaxian85
iT邦新手 4 級 ‧ 2022-02-23 15:52:14
最佳解答
小康 iT邦新手 5 級 ‧ 2022-02-23 16:05:21 檢舉

感謝你的解答!

我要發表回答

立即登入回答