Skip to content

Commit

Permalink
Merge pull request #137 from vtexdocs/feat/hide-unpublished-content
Browse files Browse the repository at this point in the history
feat: hide unpublished content
  • Loading branch information
julia-rabello authored Nov 18, 2024
2 parents b94854d + 0530a51 commit 11c8382
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/components/known-issue-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const KnownIssueCard = ({
title,
id,
module,
status,
kiStatus,
slug,
createdAt,
updatedAt,
Expand All @@ -24,9 +24,9 @@ const KnownIssueCard = ({
<Link href={`known-issues/${slug}`}>
<Flex sx={styles.container}>
<Flex sx={styles.topContainer}>
<Tag color={status}>
<Tag color={kiStatus}>
{intl.formatMessage({
id: `known_issues_filter_status.${status
id: `known_issues_filter_status.${kiStatus
.toLowerCase()
.replace(' ', '_')}`,
})}
Expand Down
19 changes: 17 additions & 2 deletions src/pages/announcements/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const getStaticProps: GetStaticProps = async ({

const logger = getLogger('Announcements')

const path = docsPaths[slug].find((e) => e.locale === locale)?.path
const path = docsPaths[slug]?.find((e) => e.locale === locale)?.path

if (!path) {
return {
Expand All @@ -198,6 +198,20 @@ export const getStaticProps: GetStaticProps = async ({
.then((res) => res.text())
.catch((err) => console.log(err))) || ''

// Serialize content and parse frontmatter
let serialized = await serialize(documentationContent, {
parseFrontmatter: true,
})

// Check if status is "PUBLISHED"
const isPublished = serialized?.frontmatter?.status === 'PUBLISHED'
if (!isPublished) {
return {
notFound: true,
}
}

// Process the rest of the data
const contributors =
(await fetch(
`https://github.com/vtexdocs/help-center-content/file-contributors/${branch}/${path}`,
Expand Down Expand Up @@ -244,7 +258,7 @@ export const getStaticProps: GetStaticProps = async ({

try {
const headingList: Item[] = []
let serialized = await serialize(documentationContent, {
serialized = await serialize(documentationContent, {
parseFrontmatter: true,
mdxOptions: {
remarkPlugins: [
Expand Down Expand Up @@ -292,6 +306,7 @@ export const getStaticProps: GetStaticProps = async ({
title: serialized.frontmatter?.title ?? seeAlsoUrl,
createdAt: String(serialized.frontmatter?.createdAt) ?? '',
updatedAt: String(serialized.frontmatter?.updatedAt) ?? '',
status: serialized.frontmatter?.status ?? '',
})
} catch (error) {}
}
Expand Down
9 changes: 6 additions & 3 deletions src/pages/announcements/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ const AnnouncementsPage: NextPage<Props> = ({ announcementsData, branch }) => {
const [sortByValue, setSortByValue] = useState<SortByType>('newest')

const filteredResult = useMemo(() => {
const data = announcementsData.filter((announcement) =>
announcement.title?.toLowerCase().includes(searchTerm.toLowerCase())
)
const data = announcementsData
.filter((announcement) => announcement.status === 'PUBLISHED')
.filter((announcement) =>
announcement.title?.toLowerCase().includes(searchTerm.toLowerCase())
)

data.sort((a, b) => {
const dateA =
Expand Down Expand Up @@ -215,6 +217,7 @@ export const getStaticProps: GetStaticProps = async ({
url: `announcements/${data.slug}`,
createdAt: String(frontmatter.createdAt),
updatedAt: String(frontmatter.updatedAt),
status: frontmatter.status ?? null,
})
} catch (error) {
logger.error(`${error}`)
Expand Down
7 changes: 7 additions & 0 deletions src/pages/docs/tracks/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ export const getServerSideProps: GetServerSideProps = async ({
},
})

// Check the frontmatter status
if (serialized.frontmatter?.status !== 'PUBLISHED') {
return {
notFound: true,
}
}

const sidebarfallback = await getNavigation()
serialized = JSON.parse(JSON.stringify(serialized))

Expand Down
7 changes: 7 additions & 0 deletions src/pages/docs/tutorial/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ export const getServerSideProps: GetServerSideProps = async ({
},
})

// Check the frontmatter status
if (serialized.frontmatter?.status !== 'PUBLISHED') {
return {
notFound: true,
}
}

serialized = JSON.parse(JSON.stringify(serialized))

logger.info(`Processing ${slug}`)
Expand Down
13 changes: 13 additions & 0 deletions src/pages/faq/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ export const getStaticProps: GetStaticProps = async ({
.then((res) => res.text())
.catch((err) => console.log(err))) || ''

// Serialize content and parse frontmatter
const serialized = await serialize(documentationContent, {
parseFrontmatter: true,
})

// Check if status is "PUBLISHED"
const isPublished = serialized?.frontmatter?.status === 'PUBLISHED'
if (!isPublished) {
return {
notFound: true,
}
}

const contributors =
(await fetch(
`https://github.com/vtexdocs/help-center-content/file-contributors/${branch}/${path}`,
Expand Down
21 changes: 12 additions & 9 deletions src/pages/faq/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ const FaqPage: NextPage<Props> = ({ faqData, branch }) => {
)

const filteredResult = useMemo(() => {
const data = faqData.filter((question) => {
const hasFilter: boolean =
filters.length === 0 || filters.includes(question.productTeam)
const hasSearch: boolean = question.title
.toLowerCase()
.includes(search.toLowerCase())

return hasFilter && hasSearch
})
const data = faqData
.filter((question) => question.status === 'PUBLISHED')
.filter((question) => {
const hasFilter: boolean =
filters.length === 0 || filters.includes(question.productTeam)
const hasSearch: boolean = question.title
.toLowerCase()
.includes(search.toLowerCase())

return hasFilter && hasSearch
})

data.sort((a, b) => {
const dateA =
Expand Down Expand Up @@ -266,6 +268,7 @@ export const getStaticProps: GetStaticProps = async ({
createdAt: String(frontmatter.createdAt),
updatedAt: String(frontmatter.updatedAt),
productTeam: frontmatter.productTeam,
status: frontmatter.status,
})
} catch (error) {
logger.error(`${error}`)
Expand Down
1 change: 1 addition & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const getStaticProps: GetStaticProps = async ({
url: `announcements/${data.slug}`,
createdAt: String(frontmatter.createdAt),
updatedAt: String(frontmatter.updatedAt),
status: frontmatter.status,
})
}
} catch (error) {
Expand Down
13 changes: 13 additions & 0 deletions src/pages/known-issues/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ export const getStaticProps: GetStaticProps = async ({
.then((res) => res.text())
.catch((err) => console.log(err))) || ''

// Serialize content and parse frontmatter
const serialized = await serialize(documentationContent, {
parseFrontmatter: true,
})

// Check if status is "PUBLISHED"
const isPublished = serialized?.frontmatter?.status === 'PUBLISHED'
if (!isPublished) {
return {
notFound: true,
}
}

const contributors =
(await fetch(
`https://github.com/vtexdocs/help-center-content/file-contributors/${branch}/${path}`,
Expand Down
36 changes: 19 additions & 17 deletions src/pages/known-issues/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,26 @@ const KnownIssuesPage: NextPage<Props> = ({ knownIssuesData, branch }) => {
const itemsPerPage = 8
const [pageIndex, setPageIndex] = useState({ curr: 1, total: 1 })
const [filters, setFilters] = useState<{
status: string[]
kiStatus: string[]
modules: string[]
}>({ status: [], modules: [] })

}>({ kiStatus: [], modules: [] })
const [search, setSearch] = useState<string>('')
const [sortByValue, setSortByValue] = useState<SortByType>('newest')
const filteredResult = useMemo(() => {
const data = knownIssuesData.filter((knownIssue) => {
const hasFilter: boolean =
(filters.status.length === 0 ||
filters.status.includes(knownIssue.status)) &&
(filters.modules.length === 0 ||
filters.modules.includes(knownIssue.module))
const data = knownIssuesData
.filter((knownIssue) => knownIssue.status === 'PUBLISHED')
.filter((knownIssue) => {
const hasFilter: boolean =
(filters.kiStatus.length === 0 ||
filters.kiStatus.includes(knownIssue.kiStatus)) &&
(filters.modules.length === 0 ||
filters.modules.includes(knownIssue.module))

const hasSearch: boolean = knownIssue.title
.toLowerCase()
.includes(search.toLowerCase())
return hasFilter && hasSearch
})
const hasSearch: boolean = knownIssue.title
.toLowerCase()
.includes(search.toLowerCase())
return hasFilter && hasSearch
})

data.sort((a, b) => {
const dateA =
Expand Down Expand Up @@ -129,10 +130,10 @@ const KnownIssuesPage: NextPage<Props> = ({ knownIssuesData, branch }) => {
tagFilter={knownIssuesStatusFilter(intl)}
checkBoxFilter={knownIssuesModulesFilters(intl)}
selectedCheckboxes={filters.modules}
selectedTags={filters.status}
selectedTags={filters.kiStatus}
onApply={(newFilters) =>
setFilters({
status: newFilters.tag,
kiStatus: newFilters.tag,
modules: newFilters.checklist,
})
}
Expand Down Expand Up @@ -243,12 +244,13 @@ export const getStaticProps: GetStaticProps = async ({
title: frontmatter.title,
module: frontmatter.tag,
slug: data.slug,
status: frontmatter.kiStatus.replace(
kiStatus: frontmatter.kiStatus.replace(
' ',
'_'
) as KnownIssueStatus,
createdAt: String(frontmatter.createdAt),
updatedAt: String(frontmatter.updatedAt),
status: frontmatter.status,
})
} catch (error) {
logger.error(`${error}`)
Expand Down
13 changes: 13 additions & 0 deletions src/pages/troubleshooting/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ export const getStaticProps: GetStaticProps = async ({
.then((res) => res.text())
.catch((err) => console.log(err))) || ''

// Serialize content and parse frontmatter
const serialized = await serialize(documentationContent, {
parseFrontmatter: true,
})

// Check if status is "PUBLISHED"
const isPublished = serialized?.frontmatter?.status === 'PUBLISHED'
if (!isPublished) {
return {
notFound: true,
}
}

const contributors =
(await fetch(
`https://github.com/vtexdocs/help-center-content/file-contributors/${branch}/${path}`,
Expand Down
15 changes: 9 additions & 6 deletions src/pages/troubleshooting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ const TroubleshootingPage: NextPage<Props> = ({
const [sortByValue, setSortByValue] = useState<SortByType>('newest')

const filteredResult = useMemo(() => {
const data = troubleshootingData.filter((troubleshoot) => {
return (
filters.length === 0 ||
troubleshoot.tags.some((tag) => filters.includes(tag))
)
})
const data = troubleshootingData
.filter((troubleshoot) => troubleshoot.status === 'PUBLISHED')
.filter((troubleshoot) => {
return (
filters.length === 0 ||
troubleshoot.tags.some((tag) => filters.includes(tag))
)
})

data.sort((a, b) => {
const dateA =
Expand Down Expand Up @@ -207,6 +209,7 @@ export async function getStaticProps({
createdAt: String(frontmatter.createdAt),
updatedAt: String(frontmatter.updatedAt),
tags: String(frontmatter.tags ?? '').split(','),
status: frontmatter.status,
})
}
} catch (error) {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/typings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,20 @@ export type KnownIssueStatus =
export type KnownIssueDataElement = {
title: string
id: string
status: KnownIssueStatus
kiStatus: KnownIssueStatus
module: string
slug: string
createdAt: string
updatedAt: string
status: 'PUBLISHED' | 'DRAFT' | 'ARCHIVED' | 'CHANGED' | string
}

export type AnnouncementDataElement = {
title: string
url: string
createdAt: string
updatedAt: string
status: 'PUBLISHED' | 'DRAFT' | 'ARCHIVED' | 'CHANGED' | string
}

export type SortByType = 'newest' | 'recently_updated'
Expand All @@ -98,6 +100,7 @@ export type FaqCardDataElement = {
createdAt: string
updatedAt: string
productTeam: string
status: 'PUBLISHED' | 'DRAFT' | 'ARCHIVED' | 'CHANGED' | string
}

export type TroubleshootingDataElement = {
Expand All @@ -106,4 +109,5 @@ export type TroubleshootingDataElement = {
tags: string[]
createdAt: string
updatedAt: string
status: 'PUBLISHED' | 'DRAFT' | 'ARCHIVED' | 'CHANGED' | string
}

0 comments on commit 11c8382

Please sign in to comment.