-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
6,289 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import Head from 'next/head'; | ||
|
||
import cfg from '../data/config.js'; | ||
|
||
const AmpLayout = ({ title, children }) => { | ||
const fullTitle = title ? `${title} | ${cfg.title}` : cfg.title; | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>{fullTitle}</title> | ||
<link rel="icon" href={cfg.favicon}></link> | ||
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1" /> | ||
</Head> | ||
<div className="markdown md:markdown-lg lg:markdown-xl">{children}</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default AmpLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,7 @@ module.exports = { | |
generateIndexSitemap: false, | ||
changefreq: null, | ||
priority: null, | ||
exclude: [ | ||
'*/amp/*' | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import Link from 'next/link'; | ||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; | ||
|
||
import { i18n } from '../../next-i18next.config.js'; | ||
import { findPost, getPublishedPosts } from '../../api/index.js'; | ||
import AmpLayout from '../../components/AmpLayout.jsx'; | ||
|
||
const AmpPost = ({ post }) => { | ||
if (!post) { | ||
return null; | ||
} | ||
|
||
const href = { | ||
pathname: '/[name]', | ||
query: { | ||
name: post.name, | ||
}, | ||
} | ||
|
||
return ( | ||
<AmpLayout title={post.header}> | ||
<h1>{post.header}</h1> | ||
<Link className="full_post_link" href={href}> | ||
Читать в полной версии → | ||
</Link> | ||
</AmpLayout> | ||
); | ||
}; | ||
|
||
export const config = { | ||
amp: true, | ||
}; | ||
|
||
export const getStaticProps = async ({ locale, params }) => { | ||
const post = await findPost(params.name, locale); | ||
|
||
if (!post) { | ||
return { | ||
notFound: true, | ||
}; | ||
} | ||
|
||
if (post.redirect_to) { | ||
return { | ||
redirect: { | ||
permanent: true, | ||
destination: post.redirect_to, | ||
}, | ||
}; | ||
} | ||
|
||
return { | ||
props: { | ||
post, | ||
...(await serverSideTranslations(locale, ['common', 'post'])), | ||
}, | ||
}; | ||
}; | ||
|
||
export const getStaticPaths = async () => { | ||
const promises = i18n.locales.map(async (locale) => { | ||
const posts = await getPublishedPosts(locale); | ||
|
||
return posts | ||
.filter(({ redirect_to }) => !redirect_to) | ||
.map(({ name }) => ({ | ||
locale, | ||
params: { name }, | ||
})); | ||
}); | ||
|
||
const allPaths = await Promise.all(promises); | ||
const paths = allPaths.flat(); | ||
|
||
return { | ||
paths, | ||
fallback: true, | ||
}; | ||
}; | ||
|
||
export default AmpPost; |
Oops, something went wrong.