From e2753ca15ae67c696b29e2cff8578df26962845a Mon Sep 17 00:00:00 2001 From: Roman Gafurov Date: Fri, 26 Aug 2022 15:02:17 +0300 Subject: [PATCH 1/2] Fix misstype in policy page url --- next-app/components/Footer.jsx | 6 ++-- next-app/public/locales/en/common.json | 2 +- next-app/public/locales/ru/common.json | 4 +-- pages/privacy-policy.md | 38 -------------------------- 4 files changed, 6 insertions(+), 44 deletions(-) delete mode 100644 pages/privacy-policy.md diff --git a/next-app/components/Footer.jsx b/next-app/components/Footer.jsx index 1dedd30d2..290b1b786 100644 --- a/next-app/components/Footer.jsx +++ b/next-app/components/Footer.jsx @@ -37,9 +37,9 @@ const Footer = () => {
  • - - - {t('footer.PrivacyPolicy.title')} + + + {t('footer.policy.title')}
  • diff --git a/next-app/public/locales/en/common.json b/next-app/public/locales/en/common.json index f7c98a05e..7120a1222 100644 --- a/next-app/public/locales/en/common.json +++ b/next-app/public/locales/en/common.json @@ -25,7 +25,7 @@ "title": "Code Battle", "url": "https://codebattle.hexlet.io/" }, - "PrivacyPolicy": { + "policy": { "title": "Privacy Policy", "url": "https://hexlet.io/pages/privacy" } diff --git a/next-app/public/locales/ru/common.json b/next-app/public/locales/ru/common.json index a7bf0999a..804b10122 100644 --- a/next-app/public/locales/ru/common.json +++ b/next-app/public/locales/ru/common.json @@ -28,9 +28,9 @@ "title": "Оценка резюме", "url": "https://cv.hexlet.io/" }, - "PrivacyPolicy": { + "policy": { "title": "Политика конфиденциальности.", - "url": "ru.https://hexlet.io/pages/privacy" + "url": "https://ru.hexlet.io/pages/privacy" } }, "disqus": { diff --git a/pages/privacy-policy.md b/pages/privacy-policy.md deleted file mode 100644 index 6e2192994..000000000 --- a/pages/privacy-policy.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -layout: page -title: Privacy Policy -permalink: /privacy-policy/ -comments: false -sitemap: false ---- - -### Information that is gathered from visitors -In common with other websites, log files are stored on the web server saving details such as the visitor's IP address, browser type, referring page and time of visit. - -Cookies may be used to remember visitor preferences when interacting with the website. - -Where registration is required, the visitor's email and a username will be stored on the server. - -### How the Information is used -The information is used to enhance the vistor's experience when using the website to display personalised content and possibly advertising. - -E-mail addresses will not be sold, rented or leased to 3rd parties. - -E-mail may be sent to inform you of news of our services or offers by us or our affiliates. - -### Visitor Options -If you have subscribed to one of our services, you may unsubscribe by following the instructions which are included in e-mail that you receive. - -You may be able to block cookies via your browser settings but this may prevent you from access to certain features of the website. - -### Cookies -Cookies are small digital signature files that are stored by your web browser that allow your preferences to be recorded when visiting the website. Also they may be used to track your return visits to the website. - -3rd party advertising companies may also use cookies for tracking purposes. - -### Google Ads -Google, as a third party vendor, uses cookies to serve ads. - -Google's use of the DART cookie enables it to serve ads to visitors based on their visit to sites they visit on the Internet. - -Website visitors may opt out of the use of the DART cookie by visiting the Google ad and content network privacy policy. From ab06ee975301925f27db9ab6d4eefb8ba64a2a87 Mon Sep 17 00:00:00 2001 From: Roman Gafurov Date: Fri, 26 Aug 2022 15:21:17 +0300 Subject: [PATCH 2/2] Form post title from file name if it isn't specified --- next-app/api/index.js | 21 ++++++++++++++++----- next-app/components/PostPageNav.jsx | 26 +++++++++++--------------- next-app/package-lock.json | 22 ++++++++++++++++++++++ next-app/package.json | 2 ++ 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/next-app/api/index.js b/next-app/api/index.js index 32ec5d6f3..b8e7c120b 100644 --- a/next-app/api/index.js +++ b/next-app/api/index.js @@ -5,22 +5,32 @@ import matter from 'gray-matter'; import remarkGfm from 'remark-gfm'; import rehypePrism from '@mapbox/rehype-prism'; import { serialize } from 'next-mdx-remote/serialize'; +import findLastIndex from 'lodash.findlastindex'; +import capitalize from 'lodash.capitalize'; import config from '../data/config.js'; +const formatNameToHeader = (name) => { + return name + .split('-') + .map(capitalize) + .join(' '); +}; + const readPost = async (filePath, basePath) => { const fileContent = await fsp.readFile(path.join(basePath, filePath), 'utf-8'); const { data, content } = matter(fileContent); const { name } = path.parse(filePath); const { title = null, header = title, description = null, summary = description, ...props } = data; const sourceUrl = `${config.repositoryUrl}/tree/main/${filePath}`; + const shortName = name.slice(11); // remove DD_MM_YYYY prefix from post file name return { - header, summary, content, sourceUrl, - name: name.slice(11), + name: shortName, + header: header || formatNameToHeader(shortName), ...props, }; }; @@ -35,7 +45,7 @@ export const getPublishedPosts = async (locale) => { .map(({ name }) => name); const promises = fileNames - .sort((a, b) => b.localeCompare(a)) + .sort((a, b) => a.localeCompare(b)) .map(async (name) => readPost(path.join(postsPath, name), dir)); return await Promise.all(promises); @@ -50,12 +60,13 @@ export const getPostsList = async (locale) => { header, summary, name, - })); + })) + .reverse(); }; export const findPost = async (name, locale) => { const posts = await getPublishedPosts(locale); - const postIndex = posts.findIndex((post) => post.name === name); + const postIndex = findLastIndex(posts, (post) => post.name === name); if (postIndex === -1) { return null; diff --git a/next-app/components/PostPageNav.jsx b/next-app/components/PostPageNav.jsx index 37eec7e30..fccfd1894 100644 --- a/next-app/components/PostPageNav.jsx +++ b/next-app/components/PostPageNav.jsx @@ -14,26 +14,22 @@ const PostPageNav = ({ nextPost, prevPost }) => { const prevHref = makeHref(prevPost.name); const nextHref = makeHref(nextPost.name); - + return (
    - {prevPost.header && ( - - - « {prevPost.header} - - - )} + + + « {prevPost.header} + +
    - {nextPost.header && ( - - - {nextPost.header} » - - - )} + + + {nextPost.header} » + +
    ); diff --git a/next-app/package-lock.json b/next-app/package-lock.json index b43c1ed79..23bc577fa 100644 --- a/next-app/package-lock.json +++ b/next-app/package-lock.json @@ -14,6 +14,8 @@ "disqus-react": "^1.1.3", "file-loader": "^6.2.0", "gray-matter": "^4.0.3", + "lodash.capitalize": "^4.2.1", + "lodash.findlastindex": "^4.6.0", "next": "^12.2.5", "next-i18next": "^11.0.0", "next-mdx-remote": "^4.1.0", @@ -4862,6 +4864,16 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, + "node_modules/lodash.capitalize": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/lodash.capitalize/-/lodash.capitalize-4.2.1.tgz", + "integrity": "sha512-kZzYOKspf8XVX5AvmQF94gQW0lejFVgb80G85bU4ZWzoJ6C03PQg3coYAUpSTpQWelrZELd3XWgHzw4Ck5kaIw==" + }, + "node_modules/lodash.findlastindex": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/lodash.findlastindex/-/lodash.findlastindex-4.6.0.tgz", + "integrity": "sha512-wghZXum6rpsr8XsE0U3PZNaLtj1Q8m8Vn/hAgHtlDlzh49ZXNpcZmVbyTFRRjkKhzPAZ4CSFyxctNIk1BLmRBg==" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -12391,6 +12403,16 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, + "lodash.capitalize": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/lodash.capitalize/-/lodash.capitalize-4.2.1.tgz", + "integrity": "sha512-kZzYOKspf8XVX5AvmQF94gQW0lejFVgb80G85bU4ZWzoJ6C03PQg3coYAUpSTpQWelrZELd3XWgHzw4Ck5kaIw==" + }, + "lodash.findlastindex": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/lodash.findlastindex/-/lodash.findlastindex-4.6.0.tgz", + "integrity": "sha512-wghZXum6rpsr8XsE0U3PZNaLtj1Q8m8Vn/hAgHtlDlzh49ZXNpcZmVbyTFRRjkKhzPAZ4CSFyxctNIk1BLmRBg==" + }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", diff --git a/next-app/package.json b/next-app/package.json index a479268a5..aff316e9d 100644 --- a/next-app/package.json +++ b/next-app/package.json @@ -22,6 +22,8 @@ "disqus-react": "^1.1.3", "file-loader": "^6.2.0", "gray-matter": "^4.0.3", + "lodash.capitalize": "^4.2.1", + "lodash.findlastindex": "^4.6.0", "next": "^12.2.5", "next-i18next": "^11.0.0", "next-mdx-remote": "^4.1.0",