Commit 7e905443 authored by tom's avatar tom

rewrite pages seo

parent 30193c74
...@@ -4,9 +4,14 @@ const isDev = env === 'development'; ...@@ -4,9 +4,14 @@ const isDev = env === 'development';
const config = Object.freeze({ const config = Object.freeze({
env, env,
isDev, isDev,
networkType: process.env.NEXT_PUBLIC_NETWORK_TYPE, network: {
networkSubtype: process.env.NEXT_PUBLIC_NETWORK_SUBTYPE, type: process.env.NEXT_PUBLIC_NETWORK_TYPE,
basePath: '/' + [ process.env.NEXT_PUBLIC_NETWORK_TYPE, process.env.NEXT_PUBLIC_NETWORK_SUBTYPE ].filter(Boolean).join('/'), subtype: process.env.NEXT_PUBLIC_NETWORK_SUBTYPE,
logo: process.env.NEXT_PUBLIC_NETWORK_LOGO,
name: process.env.NEXT_PUBLIC_NETWORK_NAME,
shortName: process.env.NEXT_PUBLIC_NETWORK_SHORT_NAME,
basePath: '/' + [ process.env.NEXT_PUBLIC_NETWORK_TYPE, process.env.NEXT_PUBLIC_NETWORK_SUBTYPE ].filter(Boolean).join('/'),
},
// TODO domain should be passed in CI during runtime // TODO domain should be passed in CI during runtime
domain: isDev ? 'http://localhost:3000' : 'https://blockscout.com', domain: isDev ? 'http://localhost:3000' : 'https://blockscout.com',
}); });
......
import availableNetworks from 'lib/networks/availableNetworks'; import appConfig from 'configs/app/config';
import featuredNetworks from 'lib/networks/featuredNetworks';
const KEY_WORDS = { const KEY_WORDS = {
BLOB: 'blob:', BLOB: 'blob:',
...@@ -16,15 +18,13 @@ const MAIN_DOMAINS = [ '*.blockscout.com', 'blockscout.com' ]; ...@@ -16,15 +18,13 @@ const MAIN_DOMAINS = [ '*.blockscout.com', 'blockscout.com' ];
const isDev = process.env.NODE_ENV === 'development'; const isDev = process.env.NODE_ENV === 'development';
function getNetworksExternalAssets() { function getNetworksExternalAssets() {
const icons = availableNetworks const icons = featuredNetworks
.filter(({ icon }) => typeof icon === 'string') .filter(({ icon }) => typeof icon === 'string')
.map(({ icon }) => new URL(icon as string)); .map(({ icon }) => new URL(icon as string));
const logos = availableNetworks const logo = appConfig.network.logo ? new URL(appConfig.network.logo) : undefined;
.filter(({ logo }) => typeof logo === 'string')
.map(({ logo }) => new URL(logo as string));
return icons.concat(logos); return logo ? icons.concat(logo) : icons;
} }
function makePolicyMap() { function makePolicyMap() {
......
...@@ -13,7 +13,7 @@ export function link(routeName: RouteName, urlParams?: Record<string, Array<stri ...@@ -13,7 +13,7 @@ export function link(routeName: RouteName, urlParams?: Record<string, Array<stri
// if we pass network type, we have to get subtype from params too // if we pass network type, we have to get subtype from params too
// otherwise getting it from config since it is not cross-chain link // otherwise getting it from config since it is not cross-chain link
const networkSubType = typeof urlParams?.network_type === 'string' ? urlParams?.network_sub_type : appConfig.networkSubtype; const networkSubType = typeof urlParams?.network_type === 'string' ? urlParams?.network_sub_type : appConfig.network.subtype;
const path = route.pattern.replace(PATH_PARAM_REGEXP, (_, paramName: string) => { const path = route.pattern.replace(PATH_PARAM_REGEXP, (_, paramName: string) => {
if (paramName === 'network_sub_type' && !networkSubType) { if (paramName === 'network_sub_type' && !networkSubType) {
......
// todo_tom delete this
import type { Network } from 'types/networks'; import type { Network } from 'types/networks';
import arbitrumIcon from 'icons/networks/icons/arbitrum.svg'; import arbitrumIcon from 'icons/networks/icons/arbitrum.svg';
...@@ -53,112 +54,66 @@ const NETWORKS: Array<Network> = (() => { ...@@ -53,112 +54,66 @@ const NETWORKS: Array<Network> = (() => {
export default NETWORKS; export default NETWORKS;
// for easy .env.example update // for easy .env.example update
// const FOR_CONFIG = JSON.stringify([ // const FEATURED_CHAINS = JSON.stringify([
// { // {
// name: 'Gnosis Chain', // title: 'Gnosis Chain',
// type: 'xdai', // basePath: '/xdai/mainnet',
// subType: 'mainnet',
// group: 'mainnets', // group: 'mainnets',
// isAccountSupported: true,
// chainId: 100,
// currency: 'xDAI',
// }, // },
// { // {
// name: 'Optimism on Gnosis Chain', // name: 'Optimism on Gnosis Chain',
// shortName: 'OoG', // basePath: '/xdai/optimism',
// type: 'xdai',
// subType: 'optimism',
// group: 'mainnets', // group: 'mainnets',
// icon: 'https://www.fillmurray.com/60/60', // icon: 'https://www.fillmurray.com/60/60',
// logo: 'https://www.fillmurray.com/240/60',
// chainId: 300,
// currency: 'xDAI',
// }, // },
// { // {
// name: 'Arbitrum on xDai', // name: 'Arbitrum on xDai',
// type: 'xdai', // basePath: '/xdai/aox',
// subType: 'aox',
// group: 'mainnets', // group: 'mainnets',
// chainId: 200,
// currency: 'xDAI',
// }, // },
// { // {
// name: 'Ethereum', // name: 'Ethereum',
// shortName: 'ETH', // basePath: '/eth/mainnet',
// type: 'eth',
// subType: 'mainnet',
// group: 'mainnets', // group: 'mainnets',
// chainId: 1,
// currency: 'ETH',
// }, // },
// { // {
// name: 'Ethereum Classic', // name: 'Ethereum Classic',
// shortName: 'ETC', // basePath: '/etx/mainnet',
// type: 'etc',
// subType: 'mainnet',
// group: 'mainnets', // group: 'mainnets',
// chainId: 61,
// currency: 'ETC',
// }, // },
// { // {
// name: 'POA', // name: 'POA',
// shortName: 'POA', // basePath: '/poa/core',
// type: 'poa',
// subType: 'core',
// group: 'mainnets', // group: 'mainnets',
// chainId: 99,
// currency: 'POA',
// isAccountSupported: true,
// nativeTokenAddress: '0x029a799563238d0e75e20be2f4bda0ea68d00172',
// }, // },
// { // {
// name: 'RSK', // name: 'RSK',
// shortName: 'RBTC', // basePath: '/rsk/mainnet',
// type: 'rsk',
// subType: 'mainnet',
// group: 'mainnets', // group: 'mainnets',
// chainId: 30,
// currency: 'RBTC',
// }, // },
// { // {
// name: 'Gnosis Chain Testnet', // name: 'Gnosis Chain Testnet',
// type: 'xdai', // basePath: '/xdai/testnet',
// subType: 'testnet',
// group: 'testnets', // group: 'testnets',
// isAccountSupported: true,
// currency: 'xDAI',
// }, // },
// { // {
// name: 'POA Sokol', // name: 'POA Sokol',
// shortName: 'POA', // basePath: '/poa/sokol',
// type: 'poa',
// subType: 'sokol',
// group: 'testnets', // group: 'testnets',
// chainId: 77,
// currency: 'SPOA',
// }, // },
// { // {
// name: 'ARTIS Σ1', // name: 'ARTIS Σ1',
// type: 'artis', // basePath: '/artis/sigma1',
// subType: 'sigma1',
// group: 'other', // group: 'other',
// chainId: 246529,
// currency: 'ATS',
// }, // },
// { // {
// name: 'LUKSO L14', // name: 'LUKSO L14',
// shortName: 'POA', // basePath: '/lukso/l14',
// type: 'lukso',
// subType: 'l14',
// group: 'other', // group: 'other',
// chainId: 22,
// currency: 'LYX',
// }, // },
// { // {
// name: 'Astar', // name: 'Astar',
// type: 'astar', // basePath: '/astar',
// group: 'other', // group: 'other',
// chainId: 22,
// currency: 'ASTR',
// }, // },
// ]); // ]);
// todo_tom delete this
import availableNetworks from 'lib/networks/availableNetworks'; import availableNetworks from 'lib/networks/availableNetworks';
interface Params { interface Params {
......
import NETWORKS from './availableNetworks';
export default function getAvailablePaths() {
return NETWORKS.map(({ type, subType }) => ({ params: { network_type: type, network_sub_type: subType || 'mainnet' } }));
}
import findNetwork from './findNetwork'; import appConfig from 'configs/app/config';
export default function getNetworkTitle({ network_type: type, network_sub_type: subType }: {network_type?: string; network_sub_type?: string}) { export default function getNetworkTitle() {
const currentNetwork = findNetwork({ network_type: type || '', network_sub_type: subType }); return appConfig.network.name + (appConfig.network.shortName ? ` (${ appConfig.network.shortName })` : '') + ' Explorer';
if (currentNetwork) {
return currentNetwork.name + (currentNetwork.shortName ? ` (${ currentNetwork.shortName })` : '') + ' Explorer';
}
return '';
} }
...@@ -21,7 +21,7 @@ export default function useNetworkNavigationItems() { ...@@ -21,7 +21,7 @@ export default function useNetworkNavigationItems() {
return { return {
...network, ...network,
url: url, url: url,
isActive: appConfig.basePath === network.basePath, isActive: appConfig.network.basePath === network.basePath,
}; };
}); });
}, [ currentRoute, currentRouteName, router.query ]); }, [ currentRoute, currentRouteName, router.query ]);
......
...@@ -3,7 +3,7 @@ import type { PageParams } from './types'; ...@@ -3,7 +3,7 @@ import type { PageParams } from './types';
import getNetworkTitle from 'lib/networks/getNetworkTitle'; import getNetworkTitle from 'lib/networks/getNetworkTitle';
export default function getSeo(params?: PageParams) { export default function getSeo(params?: PageParams) {
const networkTitle = getNetworkTitle(params || {}); const networkTitle = getNetworkTitle();
return { return {
title: params ? `Block ${ params.id } - ${ networkTitle }` : '', title: params ? `Block ${ params.id } - ${ networkTitle }` : '',
......
...@@ -14,8 +14,8 @@ type Props = { ...@@ -14,8 +14,8 @@ type Props = {
tab: BlocksProps['tab']; tab: BlocksProps['tab'];
} }
const BlocksNextPage: NextPage<Props> = ({ pageParams, tab }: Props) => { const BlocksNextPage: NextPage<Props> = ({ tab }: Props) => {
const { title } = getSeo(pageParams); const { title } = getSeo();
return ( return (
<> <>
<Head> <Head>
......
import type { PageParams } from './types';
import getNetworkTitle from 'lib/networks/getNetworkTitle'; import getNetworkTitle from 'lib/networks/getNetworkTitle';
export default function getSeo(params?: PageParams) { export default function getSeo() {
const networkTitle = getNetworkTitle(params || {});
return { return {
title: params ? `${ networkTitle } - BlockScout` : '', title: getNetworkTitle(),
}; };
} }
...@@ -3,7 +3,7 @@ import type { PageParams } from './types'; ...@@ -3,7 +3,7 @@ import type { PageParams } from './types';
import getNetworkTitle from 'lib/networks/getNetworkTitle'; import getNetworkTitle from 'lib/networks/getNetworkTitle';
export default function getSeo(params?: PageParams) { export default function getSeo(params?: PageParams) {
const networkTitle = getNetworkTitle(params || {}); const networkTitle = getNetworkTitle();
return { return {
title: params ? `Transaction ${ params.id } - ${ networkTitle }` : '', title: params ? `Transaction ${ params.id } - ${ networkTitle }` : '',
......
...@@ -21,7 +21,7 @@ export function middleware(req: NextRequest) { ...@@ -21,7 +21,7 @@ export function middleware(req: NextRequest) {
network_sub_type: networkSubtype, network_sub_type: networkSubtype,
}; };
if (appConfig.networkType !== networkType && appConfig.networkSubtype !== networkSubtype) { if (appConfig.network.type !== networkType && appConfig.network.subtype !== networkSubtype) {
const url = req.nextUrl.clone(); const url = req.nextUrl.clone();
url.pathname = `/404`; url.pathname = `/404`;
return NextResponse.rewrite(url); return NextResponse.rewrite(url);
......
...@@ -14,8 +14,8 @@ type Props = { ...@@ -14,8 +14,8 @@ type Props = {
pageParams: PageParams; pageParams: PageParams;
} }
const ApiKeysPage: NextPage<Props> = ({ pageParams }: Props) => { const ApiKeysPage: NextPage<Props> = () => {
const title = getNetworkTitle(pageParams || {}); const title = getNetworkTitle();
return ( return (
<> <>
<Head><title>{ title }</title></Head> <Head><title>{ title }</title></Head>
......
...@@ -14,8 +14,8 @@ type Props = { ...@@ -14,8 +14,8 @@ type Props = {
pageParams: PageParams; pageParams: PageParams;
} }
const CustomAbiPage: NextPage<Props> = ({ pageParams }: Props) => { const CustomAbiPage: NextPage<Props> = () => {
const title = getNetworkTitle(pageParams || {}); const title = getNetworkTitle();
return ( return (
<> <>
<Head><title>{ title }</title></Head> <Head><title>{ title }</title></Head>
......
...@@ -14,8 +14,8 @@ type Props = { ...@@ -14,8 +14,8 @@ type Props = {
pageParams: PageParams; pageParams: PageParams;
} }
const PublicTagsPage: NextPage<Props> = ({ pageParams }: Props) => { const PublicTagsPage: NextPage<Props> = () => {
const title = getNetworkTitle(pageParams || {}); const title = getNetworkTitle();
return ( return (
<> <>
<Head><title>{ title }</title></Head> <Head><title>{ title }</title></Head>
......
...@@ -14,8 +14,8 @@ type Props = { ...@@ -14,8 +14,8 @@ type Props = {
pageParams: PageParams; pageParams: PageParams;
} }
const AddressTagsPage: NextPage<Props> = ({ pageParams }: Props) => { const AddressTagsPage: NextPage<Props> = () => {
const title = getNetworkTitle(pageParams || {}); const title = getNetworkTitle();
return ( return (
<> <>
<Head><title>{ title }</title></Head> <Head><title>{ title }</title></Head>
......
...@@ -14,8 +14,8 @@ type Props = { ...@@ -14,8 +14,8 @@ type Props = {
pageParams: PageParams; pageParams: PageParams;
} }
const TransactionTagsPage: NextPage<Props> = ({ pageParams }: Props) => { const TransactionTagsPage: NextPage<Props> = () => {
const title = getNetworkTitle(pageParams || {}); const title = getNetworkTitle();
return ( return (
<> <>
<Head><title>{ title }</title></Head> <Head><title>{ title }</title></Head>
......
...@@ -14,8 +14,8 @@ type Props = { ...@@ -14,8 +14,8 @@ type Props = {
pageParams: PageParams; pageParams: PageParams;
} }
const WatchListPage: NextPage<Props> = ({ pageParams }: Props) => { const WatchListPage: NextPage<Props> = () => {
const title = getNetworkTitle(pageParams || {}); const title = getNetworkTitle();
return ( return (
<> <>
<Head> <Head>
......
...@@ -14,8 +14,8 @@ type Props = { ...@@ -14,8 +14,8 @@ type Props = {
pageParams: PageParams; pageParams: PageParams;
} }
const AddressTagsPage: NextPage<Props> = ({ pageParams }: Props) => { const AddressTagsPage: NextPage<Props> = () => {
const title = getNetworkTitle(pageParams || {}); const title = getNetworkTitle();
return ( return (
<> <>
<Head><title>{ title }</title></Head> <Head><title>{ title }</title></Head>
......
...@@ -14,8 +14,8 @@ type Props = { ...@@ -14,8 +14,8 @@ type Props = {
pageParams: PageParams; pageParams: PageParams;
} }
const AddressTagsPage: NextPage<Props> = ({ pageParams }: Props) => { const AddressTagsPage: NextPage<Props> = () => {
const title = getNetworkTitle(pageParams || {}); const title = getNetworkTitle();
return ( return (
<> <>
<Head><title>{ title }</title></Head> <Head><title>{ title }</title></Head>
......
...@@ -4,13 +4,13 @@ import React from 'react'; ...@@ -4,13 +4,13 @@ import React from 'react';
import type { NetworkGroup } from 'types/networks'; import type { NetworkGroup } from 'types/networks';
import useNetwork from 'lib/hooks/useNetwork'; import useNetwork from 'lib/hooks/useNetwork';
import NETWORKS from 'lib/networks/availableNetworks'; import featuredNetworks from 'lib/networks/featuredNetworks';
import useNetworkNavigationItems from 'lib/networks/useNetworkNavigationItems'; import useNetworkNavigationItems from 'lib/networks/useNetworkNavigationItems';
import NetworkMenuLink from './NetworkMenuLink'; import NetworkMenuLink from './NetworkMenuLink';
const TABS: Array<NetworkGroup> = [ 'mainnets', 'testnets', 'other' ]; const TABS: Array<NetworkGroup> = [ 'mainnets', 'testnets', 'other' ];
const availableTabs = TABS.filter((tab) => NETWORKS.some(({ group }) => group === tab)); const availableTabs = TABS.filter((tab) => featuredNetworks.some(({ group }) => group === tab));
const NetworkMenuPopup = () => { const NetworkMenuPopup = () => {
const selectedNetwork = useNetwork(); const selectedNetwork = useNetwork();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment