Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing some stuff #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 6 additions & 55 deletions src/components/DevDocTemplate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ import t from '../../utils/lang-utils';
const DevDocTemplate: FC<DevDocTemplateProps> = (props) => {
const { data, location } = props;
// console.log('awd', props);
const {
curPageNode,
navNode,
allAsciidoc: { edges },
} = data;
const { curPageNode, navNode } = data;
const { width, ref } = useResizeDetector();
const [params, setParams] = useState({
[TS_HOST_PARAM]: DEFAULT_HOST,
Expand Down Expand Up @@ -81,10 +77,10 @@ const DevDocTemplate: FC<DevDocTemplateProps> = (props) => {
setIsPublicSiteOpen(isPublicSite(location.search));

const paramObj = queryStringParser(location.search);
edges.map((e) => {
paramObj[e.node.parent.name] =
e.node.pageAttributes.pageid || NOT_FOUND_PAGE_ID;
});
// edges.map((e) => {
// paramObj[e.node.parent.name] =
// e.node.pageAttributes.pageid || NOT_FOUND_PAGE_ID;
// });

setParams({ ...params, ...paramObj });
}, [location.search]);
Expand All @@ -101,32 +97,6 @@ const DevDocTemplate: FC<DevDocTemplateProps> = (props) => {
);
}, [location.search, location.hash]);

const setPageContent = (pageid: string = NOT_FOUND_PAGE_ID) => {
// check if url query param is having pageid or not
if (pageid) {
// fetch edge id for specified pageid in the url
const edgeIndex = edges.findIndex(
(i) => i.node.pageAttributes[TS_PAGE_ID_PARAM] === pageid,
);

// check if we have corresponding document to serve if not redirect to 404
if (edgeIndex > -1) {
// get and set page title
setDocTitle(
edges[edgeIndex].node.document.title ||
edges[edgeIndex].node.pageAttributes.title,
);

// get and set doc page content with dynamic data replaced
setDocContent(
passThroughHandler(edges[edgeIndex].node.html, params),
);
} else {
// pageid not found redirect
setPageContent(NOT_FOUND_PAGE_ID);
}
}
};
const setPageContentFromSingleNode = (node: AsciiDocNode) => {
setDocTitle(node.document.title || node.pageAttributes.title);

Expand Down Expand Up @@ -254,6 +224,7 @@ const DevDocTemplate: FC<DevDocTemplateProps> = (props) => {
isMaxMobileResolution={isMaxMobileResolution}
setDarkMode={setDarkMode}
isDarkMode={isDarkMode}
pageId={params[TS_PAGE_ID_PARAM]}
/>
<div
className="documentBody"
Expand Down Expand Up @@ -333,26 +304,6 @@ export const query = graphql`
}
html
}
allAsciidoc(sort: { fields: [document___title], order: ASC }) {
edges {
node {
document {
title
}
pageAttributes {
pageid
title
description
}
parent {
... on File {
name
}
}
html
}
}
}
}
`;

Expand Down
2 changes: 1 addition & 1 deletion src/components/LeftSidebar/helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const collapseAndExpandLeftNav = (
export const getAllPageIds = (navContent: string): string[] => {
const divElement = document.createElement('div');
divElement.innerHTML = navContent;
const allPageIds = [];
const allPageIds: string[] = [];
divElement.querySelectorAll('a').forEach((link: HTMLAnchorElement) => {
const splitArr = link.href.split('?');
if (splitArr.length > 1) {
Expand Down
1 change: 1 addition & 0 deletions src/components/LeftSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const LeftSideBar = (props: {
setLeftNavOpen: Function;
isPublicSiteOpen: boolean;
setDarkMode: Function;
pageId?: string;
}) => {
const params = queryStringParser(props.location.search);
const [navContent, setNavContent] = useState('');
Expand Down