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

feat(v2): pluralize posts on tag's page #2263

Merged
merged 4 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions packages/docusaurus-theme-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"react": "^16.8.4",
"react-dom": "^16.8.4"
},
"bundledDependencies": [
"@docusaurus/utils"
],
"engines": {
"node": ">=10.9.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React from 'react';
import Layout from '@theme/Layout';
import BlogPostItem from '@theme/BlogPostItem';
import Link from '@docusaurus/Link';
import {pluralize} from '@docusaurus/utils';

function BlogTagsPostPage(props) {
const {metadata, items} = props;
Expand All @@ -23,7 +24,8 @@ function BlogTagsPostPage(props) {
<div className="row">
<div className="col col--8 col--offset-2">
<h1>
{count} post(s) tagged with &quot;{tagName}&quot;
{count} {pluralize(count, 'post')} tagged with &quot;{tagName}
&quot;
</h1>
<Link href={allTagsPath}>View All Tags</Link>
<div className="margin-vert--xl">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useBaseUrl from '@docusaurus/useBaseUrl';
import useLockBodyScroll from '@theme/hooks/useLockBodyScroll';
import Link from '@docusaurus/Link';
import isInternalUrl from '@docusaurus/utils'; // eslint-disable-line import/no-extraneous-dependencies
import {isInternalUrl} from '@docusaurus/utils';

import styles from './styles.module.css';

Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/client/exports/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React, {useEffect, useRef} from 'react';
import {NavLink} from 'react-router-dom';
import isInternalUrl from '@docusaurus/utils';
import {isInternalUrl} from '@docusaurus/utils';

function Link(props) {
const {to, href} = props;
Expand Down
7 changes: 6 additions & 1 deletion packages/docusaurus/src/client/exports/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
export default function isInternalUrl(url) {

export function isInternalUrl(url) {
return /^\/(?!\/)/.test(url);
}

export function pluralize(count, word) {
return count > 1 ? `${word}s` : word;
}