fotcamp / tech-blog

Fotcamp Tech Blog
https://blog.fin-hub.co.kr/
1 stars 0 forks source link

fix: md-to-markdown #16

Closed widse closed 1 month ago

widse commented 1 month ago

πŸ“ PR μœ ν˜•

πŸ“ PR μ„€λͺ…

notion data μ»΄ν¬λ„ŒνŠΈ λ³€ν™˜

κ΄€λ ¨λœ 이슈 λ„˜λ²„

βœ… μž‘μ—… λͺ©λ‘

μ»€μŠ€ν…€ μ»΄ν¬λ„ŒνŠΈ 연동

css μˆ˜μ •

MRν•˜κΈ° 전에 ν™•μΈν•΄μ£Όμ„Έμš”

πŸ“š λ…Όμ˜μ‚¬ν•­

callout component

image

Callout 의 경우 μ‚¬μš©ν•˜λŠ” λΌμ΄λΈŒλŸ¬λ¦¬μ—μ„œ μ§€μ›ν•˜μ§€ μ•Šμ•„ λ³΅μž‘ν•˜κ²Œ 처리 ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

function customizeMdBlocks(blocks: any[]) {
  return blocks.map(block => {
    if (block.type === "callout") {
      const content = block.parent.replace(/>\s*(\S+)\s*/, "").trim();
      const newContent = `> [callout] ${content}`;

      return {
        ...block,
        type: "blockquote",
        parent: newContent
      };
    }
    return block;
  });
}

1차둜 λ…Έμ…˜ 데이터λ₯Ό md block으둜 λ³€ν™˜ μ‹œ 쀑간에 [callout] μ΄λΌλŠ” ν‚€μ›Œλ“œλ₯Ό λ„£μ–΄μ„œ μ•„λž˜μ™€ 같이 λΆ„κΈ°λ‘œ λ°›μ•„ 처리 ν•  수 있게 ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

 blockquote: ({ node, ...props }) => {
            const content = getChildrenContent(props.children);

            if (content.startsWith("[callout]")) {
              return <Callout>{content.substring("[callout]".length).trim()}</Callout>;
            }

            return <BlockQuote {...props} />;

Anchor component

image

Anchor의 경우 κ·ΈλŒ€λ‘œ μ‚¬μš© ν•  경우 μ΄λ™ν•˜λ €λŠ” κ²½λ‘œκ°€ ν‘œμ‹œλ˜μ–΄ μ•„λž˜μ™€ μ½”λ“œλ‘œ μ΄λ™ν•˜λ €λŠ” νŽ˜μ΄μ§€μ—μ„œ title, og title 등을 νŒŒμ‹±ν•˜μ—¬ ν…μŠ€νŠΈλ‘œ λ³΄μ—¬μ£Όκ²Œ μ²˜λ¦¬ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

export const Anchor = (props: any) => {
  const parse = async () => {
    try {
      const response = await fetch(props.href);
      const text = await response.text();

      const title = text.match(/<title[^>]*>(.*?)<\/title>/i);
      if (title && title[1]) return title[1];

      const ogTitle = text.match(/<meta\s+property="og:title"\s+content="(.*?)"/i);
      if (ogTitle && ogTitle[1]) return ogTitle[1];

      return null;
    } catch (error) {
      console.error("Error fetching title:", error);
    }
  };

  return <Link {...props}>{parse() || props.children}</Link>;
};

μΆ”κ°€ κ³ λ € 사항