All files / components/Content index.tsx

100% Statements 14/14
83.33% Branches 5/6
100% Functions 5/5
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94                            7x 7x 7x           7x   7x       3x 3x     1x       3x 1x 1x       7x         7x 7x                                                                                          
import React, { Component } from "react";
import lozad from "lozad";
 
import { isBrowser } from "@/utils";
import * as style from "./index.module.scss";
 
type Props = {
  post: string;
  useAi?: boolean;
};
 
class Content extends Component<Props> {
  private post: string;
  constructor(props: Props) {
    super(props);
    const { post } = this.props;
    this.post = post;
  }
 
  componentDidMount() {
    // lazy loads elements with default selector as '.lozad'
    // Prevent WebPack build fail
    Eif (isBrowser()) {
      // Initialize library
      const observer = lozad(".lozad", {
        load(el) {
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore
          el.src = el.dataset.src;
          if (el.getAttribute("data-background-image")) {
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-ignore
            el.style.backgroundImage = el.getAttribute("data-background-image");
          }
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore
          el.onload = () => {
            el.classList.add("animated");
            el.classList.add("fadeIn");
          };
        },
      });
      observer.observe();
    }
  }
 
  render() {
    const { post, useAi } = this.props;
    return (
      <>
        <div className={style.contentWhiteInner} data-testid="innerHTML">
          {useAi && (
            <aside className={style.aiDisclaimer}>
              <span className={style.aiDisclaimerIcon}>!</span>
              <p className={style.aiDisclaimerText}>
                この記事は筆者(
                <a
                  href="https://portfolio.tubone-project24.xyz/"
                  target="_blank"
                  rel="noopener noreferrer"
                >
                  tubone
                </a>
                )が
                <a
                  href="https://github.com/tubone24/whisper-realtime"
                  target="_blank"
                  rel="noopener noreferrer"
                >
                  whisper-realtime
                </a>
                を利用し文字起こしした内容をもとにAIにて記事の執筆を実施したものです。
              </p>
            </aside>
          )}
          <div dangerouslySetInnerHTML={{ __html: post }} />
        </div>
        <div className={style.contentWhiteInner}>
          <h2>tubone24にラーメンを食べさせよう!</h2>
          <p>ぽちっとな↓</p>
          <a href="https://www.buymeacoffee.com/tubone24">
            <img
              src="https://img.buymeacoffee.com/button-api/?text=Buy me a ramen&emoji=🍜&slug=tubone24&button_colour=40DCA5&font_colour=ffffff&font_family=Lato&outline_colour=000000&coffee_colour=FFDD00"
              alt="Buy me a ramen"
            />
          </a>
        </div>
      </>
    );
  }
}
 
export default Content;