Skip to content

Commit

Permalink
add content blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
MooKorea committed Oct 27, 2023
1 parent 33dae66 commit beb32a0
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 5 deletions.
15 changes: 15 additions & 0 deletions public/images/NoteIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions public/images/SeeAlsoIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions public/images/WarningIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 31 additions & 5 deletions src/assets/pages/documentation/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useContext, useEffect, useState } from "react";
import { PageChange } from ".";
import { motion } from "framer-motion";
import Image from "./Image";
import parse from "html-react-parser";
import parse, { domToReact } from "html-react-parser";

export default function Body({ initialPage }) {
const [page, setPage] = useContext(PageChange);
Expand All @@ -12,9 +12,9 @@ export default function Body({ initialPage }) {
(async () => {
setHTML(null);
let p = page;
if (initialPage === undefined) return
if (initialPage === undefined) return;
if (page === "home") {
p = initialPage.slice(0, -3)
p = initialPage.slice(0, -3);
}
const data = await fetch(`/docs/${p}.html`);
if (data.status === 404) {
Expand All @@ -27,7 +27,7 @@ export default function Body({ initialPage }) {
}, [page, initialPage]);

const options = {
replace: ({ name, attribs, children }) => {
replace: ({ name, attribs, children, data }) => {
//convert all images to clickable images
if (name === "img") {
return <Image attribs={attribs} />;
Expand All @@ -40,7 +40,33 @@ export default function Body({ initialPage }) {
</a>
);
}
}

//content blocks
function handleContentBlock(data) {
const type = ["Note", "See Also", "Warning"];
for (let i = 0; i < type.length; i++) {
if (data?.slice(0, type[i].length + 1) === `${type[i].toUpperCase()}:`) {
return type[i];
}
}
return false;
}

if ((name === "p" || name === "li") && children[0].data !== undefined) {
const type = handleContentBlock(children[0].data);
if (!type) return;
const typeNoSpace = type.replace(" ", "");
return (
<div className="block">
<div className={`header ${typeNoSpace}Header`}>
<img src={`/images/${typeNoSpace}Icon.svg`} className="icon" />
{type}
</div>
<p>{domToReact(children, options)}</p>
</div>
);
}
},
};

const handleLoader = () => {
Expand Down
38 changes: 38 additions & 0 deletions src/assets/styles/documentation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,44 @@
cursor: zoom-out;
}
}

.block {
background-color: #d9dde2;
border-radius: 0.4em;
overflow: hidden;
margin-block: 0.8em;
p {
margin-inline: 0.7em;
}

.header {
color: #ffffff;
font-weight: 700;
letter-spacing: 0.6px;
padding-left: 0.7em;
padding-block: 0.2em;
display: flex;
align-items: center;
gap: 0.5em;
}

.icon {
height: 20px;
filter: invert(1);
}

.NoteHeader {
background-color: $noteCol;
}
.SeeAlsoHeader {
background-color: $seeAlsoCol;
}
.WarningHeader {
background-color: $warningCol;
}
}


}

.documentation-container .sidebar {
Expand Down

0 comments on commit beb32a0

Please sign in to comment.