|
@@ -1,6 +1,6 @@
|
|
|
import React, { useEffect } from 'react';
|
|
import React, { useEffect } from 'react';
|
|
|
|
|
|
|
|
-import { pagePathUtils } from '@growi/core';
|
|
|
|
|
|
|
+import { isClient, pagePathUtils } from '@growi/core';
|
|
|
import { isValidObjectId } from 'mongoose';
|
|
import { isValidObjectId } from 'mongoose';
|
|
|
import {
|
|
import {
|
|
|
NextPage, GetServerSideProps, GetServerSidePropsContext,
|
|
NextPage, GetServerSideProps, GetServerSidePropsContext,
|
|
@@ -11,6 +11,7 @@ import { useRouter } from 'next/router';
|
|
|
// import { PageAlerts } from '~/components/PageAlert/PageAlerts';
|
|
// import { PageAlerts } from '~/components/PageAlert/PageAlerts';
|
|
|
// import { PageComments } from '~/components/PageComment/PageComments';
|
|
// import { PageComments } from '~/components/PageComment/PageComments';
|
|
|
// import { useTranslation } from '~/i18n';
|
|
// import { useTranslation } from '~/i18n';
|
|
|
|
|
+import { isPopulated } from '~/interfaces/common';
|
|
|
import { CrowiRequest } from '~/interfaces/crowi-request';
|
|
import { CrowiRequest } from '~/interfaces/crowi-request';
|
|
|
// import { renderScriptTagByName, renderHighlightJsStyleTag } from '~/service/cdn-resources-loader';
|
|
// import { renderScriptTagByName, renderHighlightJsStyleTag } from '~/service/cdn-resources-loader';
|
|
|
// import { useIndentSize } from '~/stores/editor';
|
|
// import { useIndentSize } from '~/stores/editor';
|
|
@@ -136,6 +137,13 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
|
|
|
useSWRxCurrentPage(undefined, pageWithMeta?.data); // store initial data
|
|
useSWRxCurrentPage(undefined, pageWithMeta?.data); // store initial data
|
|
|
useSWRxPageInfo(pageWithMeta?.data._id, undefined, pageWithMeta?.meta); // store initial data
|
|
useSWRxPageInfo(pageWithMeta?.data._id, undefined, pageWithMeta?.meta); // store initial data
|
|
|
|
|
|
|
|
|
|
+ // sync pathname
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (isClient() && window.location.pathname !== props.currentPathname) {
|
|
|
|
|
+ router.replace(props.currentPathname, undefined, { shallow: true });
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [props.currentPathname, router]);
|
|
|
|
|
+
|
|
|
const classNames: string[] = [];
|
|
const classNames: string[] = [];
|
|
|
// switch (editorMode) {
|
|
// switch (editorMode) {
|
|
|
// case EditorMode.Editor:
|
|
// case EditorMode.Editor:
|
|
@@ -211,6 +219,9 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
|
|
|
<footer>
|
|
<footer>
|
|
|
{/* <PageComments /> */}
|
|
{/* <PageComments /> */}
|
|
|
PageComments
|
|
PageComments
|
|
|
|
|
+ <p>
|
|
|
|
|
+ { pageWithMeta != null && isPopulated(pageWithMeta.data.revision) && pageWithMeta.data.revision.body }
|
|
|
|
|
+ </p>
|
|
|
</footer>
|
|
</footer>
|
|
|
|
|
|
|
|
</BasicLayout>
|
|
</BasicLayout>
|
|
@@ -242,6 +253,14 @@ async function injectPageInformation(context: GetServerSidePropsContext, props:
|
|
|
props.isNotFound = true;
|
|
props.isNotFound = true;
|
|
|
logger.warn(`Page is ${props.isForbidden ? 'forbidden' : 'not found'}`, currentPathname);
|
|
logger.warn(`Page is ${props.isForbidden ? 'forbidden' : 'not found'}`, currentPathname);
|
|
|
}
|
|
}
|
|
|
|
|
+ else {
|
|
|
|
|
+ // set shouldRedirectToParmalink
|
|
|
|
|
+ const isToppage = pagePathUtils.isTopPage(props.currentPathname);
|
|
|
|
|
+ const shouldRedirectToParmalink = !isToppage && !isValidObjectId(pageIdStr);
|
|
|
|
|
+ if (shouldRedirectToParmalink) {
|
|
|
|
|
+ props.currentPathname = `/${page._id}`;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
await (page as unknown as PageModel).populateDataToShowRevision();
|
|
await (page as unknown as PageModel).populateDataToShowRevision();
|
|
|
props.pageWithMetaStr = JSON.stringify(result);
|
|
props.pageWithMetaStr = JSON.stringify(result);
|