import HomePage from "../../components/home-page";
import ICard from "../../components/introduction-card";
import WCard from "../../components/werefox-card";
import PBlock from "../../components/page-block";

// Grab data from a static YAML file
export async function getStaticProps() {
  const fs = require("fs");
  const yaml = require("js-yaml");
  let INTRODUCTION = {};
  let SUBDOMAINS = {};

  try {
    let fileContent = fs.readFileSync("./data/local/introduction.yml", "utf8");
    INTRODUCTION = yaml.load(fileContent);
    fileContent = fs.readFileSync("./data/local/subdomains.yml", "utf8");
    SUBDOMAINS = yaml.load(fileContent);
  } catch (e) {
    console.log(e);
  }
  return {
    props: {
      INTRODUCTION,
      SUBDOMAINS,
    },
  };
}

export default function Home({ INTRODUCTION, SUBDOMAINS }) {
  // let introarray = INTRODUCTION["intro"].split("\n");
  // introarray = introarray.slice(0, introarray.length - 1);
  // const introdict = Object.assign({}, introarray);

  return (
    <HomePage page_title="Local Network Subdomains" card_title="Local Network Subdomains">
      <WCard title="Welcome to local.werefox">
        <ICard introduction={INTRODUCTION.intro} emoji_paths={{}} />
      </WCard>
      <WCard title="Subdomains">
        <PBlock pages={SUBDOMAINS} />
      </WCard>
    </HomePage>
  );
}
