From 7882d04d6ffa2cc8315cea5c41f5f8d8c0324a6d Mon Sep 17 00:00:00 2001 From: Mateusz Sienkan Date: Fri, 22 Apr 2022 03:55:43 +0200 Subject: [PATCH] fix: broken crosslinks (#81, #74) Some of the links are formatted as `function_name()` or `library::function_name()` instead of just `function_name`. This is the convention in the tidyverse packages' docs. This change simply removes the brackets and splits the library and function names. Link to `tidyselect::vars_pull()` from tidyr: Before: /link/tidyselect::vars_pull()?package=tidyr After: /link/vars_pull?package=tidyselect --- pages/link/[topic].tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pages/link/[topic].tsx b/pages/link/[topic].tsx index b143e57..f9e8f62 100644 --- a/pages/link/[topic].tsx +++ b/pages/link/[topic].tsx @@ -1,4 +1,5 @@ import { GetServerSideProps } from 'next'; + import { API_URL } from '../../lib/utils'; export default function genericLinkPage() { @@ -6,12 +7,23 @@ export default function genericLinkPage() { } export const getServerSideProps: GetServerSideProps = async ({ - params: { topic }, - query: { package: packageName, version }, + params, + query, }) => { + let topic = Array.isArray(params.topic) ? params.topic[0] : params.topic; + let packageName = Array.isArray(query.package) + ? query.package[0] + : query.package; + + topic = topic.replace(/\(\)$/, ''); + + if (topic.includes('::')) { + [packageName, topic] = topic.split('::'); + } + try { const res = await fetch( - `${API_URL}/link/${topic}?package=${packageName}&version=${version}`, + `${API_URL}/link/${topic}?package=${packageName}&version=${query.version}`, ); return {