next#GetStaticPaths TypeScript Examples
The following examples show how to use
next#GetStaticPaths.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: [slug].tsx From coindrop with GNU General Public License v3.0 | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const posts = getAllPosts(['slug']);
return {
paths: posts.map(post => ({
params: {
slug: post.slug,
},
})),
fallback: false,
};
}
Example #2
Source File: index.tsx From next-sitemap with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const pages = [
{ id: 'team', locale: 'en-US' },
{ id: 'team', locale: 'fr' },
{ id: 'team', locale: 'nl-NL' },
{ id: 'careers', locale: 'en-US' },
{ id: 'careers', locale: 'fr' },
{ id: 'careers', locale: 'nl-BE' },
]
return {
paths: pages.map(({ id, locale }) => ({
params: {
dynamic: id,
},
locale,
})),
fallback: false,
}
}
Example #3
Source File: [slug].tsx From space-traveling with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const prismic = getPrismicClient();
const posts = await prismic.query([
Prismic.Predicates.at('document.type', 'posts'),
]);
const paths = posts.results.map(post => {
return {
params: {
slug: post.uid,
},
};
});
return {
paths,
fallback: true,
};
}
Example #4
Source File: [page].tsx From portfolio with MIT License | 6 votes |
getStaticPaths: GetStaticPaths<{ page: string }> = async () => {
const totalPosts = await getAllFilesFrontMatter('blog');
const totalPages = Math.ceil(totalPosts.length / POSTS_PER_PAGE);
const paths = Array.from({ length: totalPages }, (_, i) => ({
params: { page: (i + 1).toString() },
}));
return {
paths,
fallback: false,
};
}
Example #5
Source File: [id].tsx From xstate-catalogue with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const fs = await import('fs');
const path = await import('path');
const machinesPath = path.resolve(process.cwd(), 'lib/machines');
const machines = fs.readdirSync(machinesPath);
return {
fallback: false,
paths: machines
.filter((machine) => machine.endsWith('.ts'))
.map((fileName) => {
return {
params: {
id: fileName.replace(machinePathRegex, ''),
},
};
}),
};
}
Example #6
Source File: [to].tsx From videotranscode.space with Apache License 2.0 | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const formatKeys = Object.keys(formats)
const paths: ParamPaths = formatKeys.map(format => {
return { params: { to: format.toLowerCase() } }
})
const fromToPaths = formatKeys.map(format => {
const fromPaths: ParamPaths = formatKeys
.filter(currentFormat => currentFormat !== format)
.map(currentFormat => {
return {
params: {
to: `${currentFormat.toLowerCase()}-to-${format.toLowerCase()}`
}
}
})
return fromPaths
}) // An Array of ParamPaths, which map to something like mp4-to-mov
const flattedArray = Array.prototype.concat.apply([], fromToPaths)
return {
paths: [...paths, ...flattedArray],
fallback: false // See the "fallback" section below
}
}
Example #7
Source File: [page].tsx From oxen-website with GNU General Public License v3.0 | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
// Get paths to all pages stored in navigation constants.
// Contentful can edit entries but cannot add/remove without touching code.
const navigationPaths: IPath[] = Object.values(NAVIGATION.SIDE_MENU_ITEMS)
.filter(item => {
return item.hasOwnRoute === undefined && isLocal(item.href);
})
.map(item => ({
params: { page: item.href.slice(1) },
}));
const cms = new CmsApi();
const posts: IPost[] = [];
let currentPage = 1;
let foundAllPosts = false;
// Contentful only allows 100 at a time
while (!foundAllPosts) {
const { entries: _posts } = await cms.fetchBlogEntries(100, currentPage);
if (_posts.length === 0) {
foundAllPosts = true;
continue;
}
posts.push(..._posts);
currentPage++;
}
const postPaths: IPath[] = posts.map(post => ({
params: { page: post.slug },
}));
return { paths: [...navigationPaths, ...postPaths], fallback: 'blocking' };
}
Example #8
Source File: [[...catchall]].tsx From plasmic with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const pageModules = await PLASMIC.fetchPages();
return {
paths: pageModules.map((mod) => ({
params: {
catchall: mod.path.substring(1).split("/"),
},
})),
// Turn on "fallback: 'blocking'" if you would like new paths created
// in Plasmic to be automatically available
fallback: false,
};
}
Example #9
Source File: [section].tsx From frontend with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => ({
paths: [
{ params: { section: 'common-questions' } },
{ params: { section: 'campaigns' } },
{ params: { section: 'donations' } },
{ params: { section: 'recurring-donations' } },
{ params: { section: 'potential-fraud' } },
{ params: { section: 'attracting-donators' } },
{ params: { section: 'corporate-partnership' } },
],
fallback: true,
})
Example #10
Source File: [piggybankName].tsx From coindrop with GNU General Public License v3.0 | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const piggybankDocumentReferences = await db()
.collection('piggybanks')
.listDocuments();
const piggybankIds = piggybankDocumentReferences.map(ref => ref.id);
const paths = piggybankIds.map(piggybankId => ({ params: { piggybankName: piggybankId } }));
return {
paths,
fallback: 'blocking',
};
}
Example #11
Source File: [slug].tsx From jeffjadulco.com with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const posts = await getAllFrontMatters()
return {
paths: posts.map(post => ({
params: {
slug: post.slug,
},
})),
fallback: false,
}
}
Example #12
Source File: [page].tsx From coindrop with GNU General Public License v3.0 | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const posts = getAllPosts([]);
const pageTotal = Math.ceil(posts.length / postsPerPage);
const pages = [];
let counter = 1;
do {
pages.push(counter.toString());
counter += 1;
} while (counter <= pageTotal);
return {
paths: pages.map(page => ({
params: {
page,
},
})),
fallback: false,
};
}
Example #13
Source File: [slug].tsx From samuelkraft-next with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const tags = allPosts
.map(p => p.tags)
.flat()
.filter(Boolean)
.map(tag => ({ params: { slug: slugify(tag, { lower: true }) } }))
return {
paths: tags,
fallback: false,
}
}
Example #14
Source File: [id].tsx From blog with GNU General Public License v3.0 | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
return {
paths: (await getPostsMetdata()).map(meta => {
return {
params: {
id: meta.id,
}
};
}),
fallback: false
};
}
Example #15
Source File: [...slug].tsx From next-cms-ghost with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const { enable, maxNumberOfPosts, maxNumberOfPages } = processEnv.isr
const limitForPosts = (enable && { limit: maxNumberOfPosts }) || undefined
const limitForPages = (enable && { limit: maxNumberOfPages }) || undefined
const posts = await getAllPosts(limitForPosts)
const pages = await getAllPages(limitForPages)
const settings = await getAllSettings()
const { url: cmsUrl } = settings
const postRoutes = (posts as GhostPostsOrPages).map((post) => {
const collectionPath = collections.getCollectionByNode(post)
const { slug, url } = post
return resolveUrl({ cmsUrl, collectionPath, slug, url })
})
let contactPageRoute: string | null = null
if (processEnv.contactPage) {
const contactPage = { ...defaultPage, ...customPage }
const { slug, url } = contactPage
contactPageRoute = resolveUrl({ cmsUrl, slug, url })
}
const customRoutes = (contactPageRoute && [contactPageRoute]) || []
const pageRoutes = (pages as GhostPostsOrPages).map(({ slug, url }) => resolveUrl({ cmsUrl, slug, url }))
const paths = [...postRoutes, ...pageRoutes, ...customRoutes]
return {
paths,
fallback: enable && 'blocking',
}
}
Example #16
Source File: [...slug].tsx From log4brains with Apache License 2.0 | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const adrs = await getLog4brainsInstance().searchAdrs();
const paths = adrs.map((adr) => {
return { params: { slug: adr.slug.split("/") } };
});
return {
paths,
fallback:
process.env.LOG4BRAINS_PHASE === "initial-build" ? "blocking" : false
};
}
Example #17
Source File: [slug].tsx From vignette-web with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async ({ locales }) => {
const paths: { params: { slug: string }; locale: string }[] = []
for (const locale of locales as string[]) {
allPosts.map((post) => {
paths.push({ params: { slug: post.slug }, locale })
})
}
return {
paths,
fallback: false,
}
}
Example #18
Source File: [[...slug]].tsx From Insomniac-NextJS-boilerplate with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const client = initializeApollo();
const { data } = await client.query({
query: AllPagesSlugDocument,
});
const paths = data.pages.nodes.map((item: { uri: string }) => {
return {
params: { slug: item.uri.split('/').filter((slug) => slug !== '') },
};
});
paths.push({ params: { slug: [''] } });
return { paths, fallback: false };
}
Example #19
Source File: [page].tsx From nextjs-netlify-blog-template with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const pages = Math.ceil(countPosts() / config.posts_per_page);
const paths = Array.from(Array(pages - 1).keys()).map((it) => ({
params: { page: (it + 2).toString() },
}));
return {
paths: paths,
fallback: false,
};
}
Example #20
Source File: [slug].tsx From exevo-pan with The Unlicense | 6 votes |
getStaticPaths: GetStaticPaths = async ({ locales }) => {
const allPostData = await BlogClient.getEveryPostLocale({})
const paths: PathItem[] = []
allPostData.en.forEach(({ slug }) => {
locales?.forEach((locale) => {
paths.push({
params: {
slug,
},
locale,
})
})
})
return {
paths,
fallback: false,
}
}
Example #21
Source File: [id].tsx From next-translate-routes with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async ({ locales }) => {
// Get the paths we want to pre-render based on users
const paths = locales.reduce(
(acc, locale) => [
...acc,
...sampleUserData.map((user) => ({
params: { id: user.id.toString() },
locale,
})),
],
[],
)
// We'll pre-render only these paths at build time.
// { fallback: false } means other routes should 404.
return { paths, fallback: false }
}
Example #22
Source File: [slug].tsx From aljoseph.co with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
return {
paths: posts.map((post) => {
return {
params: {
slug: post.slug
}
};
}),
fallback: false
};
}
Example #23
Source File: [slug].tsx From dhafit.xyz with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
return {
paths: getAllBlogs().map((post) => ({
params: {
slug: post.permalink,
},
})),
fallback: false,
};
}
Example #24
Source File: [carId].tsx From master-frontend-lemoncode with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
return {
paths: [
{ params: { carId: '1' } },
{ params: { carId: '2' } },
{ params: { carId: '3' } },
],
fallback: true,
};
}
Example #25
Source File: [slug].tsx From dhafit.xyz with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
return {
paths: getAllProjects().map((post) => ({
params: {
slug: post.permalink,
},
})),
fallback: false,
};
}
Example #26
Source File: [slug].tsx From BloggerWeb with GNU General Public License v3.0 | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const paths = postFilePaths
// Remove file extensions for page paths
.map((path) => path.replace(/\.mdx?$/, ''))
// Map the path into the static paths object required by Next.js
.map((slug) => ({ params: { slug } }));
return {
paths,
fallback: false,
};
}
Example #27
Source File: [id].tsx From crypto-fees with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
await ensureListLoaded();
return {
paths: [
...getIDs().map((id: string) => ({ params: { id } })),
...getBundleIDs().map((id: string) => ({ params: { id } })),
],
fallback: false,
};
}
Example #28
Source File: [subpage].tsx From roamjs-com with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () =>
axios
.get(`${API_URL}/request-path?sub=true`)
.then((r) => ({
paths: r.data.paths.map((params) => ({
params,
})),
fallback: false,
}))
.catch(() => ({
paths: [],
fallback: false,
}))
Example #29
Source File: [slug].tsx From podcastr with MIT License | 6 votes |
getStaticPaths: GetStaticPaths = async () => {
const { data } = await api.get('episodes', {
params: {
_limit: 12,
_sort: 'publised_at',
_order: 'desc'
}
});
const paths = data.map(episode => {
return {
params: {
slug: episode.id
}
}
})
return {
paths,
fallback: 'blocking'
}
}