Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions website/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function createAposConfig() {
},
// Enable local SEO module with GTM integration
'@apostrophecms/seo': {},
'@apostrophecms/sitemap': {},
'@apostrophecms/global': {},
// Make getEnv function available to templates
'@apostrophecms/template': {
Expand All @@ -79,6 +80,7 @@ function createAposConfig() {

// Add global data module
'global-data': {},
'robots': {},

// Shared constants module
'@apostrophecms/shared-constants': {},
Expand Down
5 changes: 5 additions & 0 deletions website/modules/@apostrophecms/sitemap/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
options: {
cacheLifetime: 60 * 60,
},
};
34 changes: 34 additions & 0 deletions website/modules/case-studies-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,36 @@ const runSetupIndexData = async function (self, req) {
}
};

const buildIndexSeoData = function (req) {
const query = req.query || {};
const hasFilterParams =
Boolean(query.search) ||
Boolean(query.industry) ||
Boolean(query.stack) ||
Boolean(query.caseStudyType) ||
Boolean(query.partner);
const pageNumber = Number(query.page || 1);
const hasPaginationParam = Number.isFinite(pageNumber) && pageNumber > 1;
const shouldNoindex = hasFilterParams || hasPaginationParam;
let pageUrl = '/cases';
if (req.data && req.data.page && req.data.page.slug) {
pageUrl = req.data.page.slug;
}
let robots = 'index,follow';
if (shouldNoindex) {
robots = 'noindex,follow';
}
return {
canonicalUrl: pageUrl,
robots,
};
};

const runSetupIndexSeoData = function (req) {
req.data ||= {};
req.data.caseListingSeo = buildIndexSeoData(req);
};

const runSetupShowData = async function (self, req) {
try {
const navigation = await NavigationService.getNavigationDataForPage(
Expand Down Expand Up @@ -219,6 +249,7 @@ module.exports = {
await self.resolveSearchRelationships(req);
await self.applyEnhancedSearchResults(req);
await self.setupIndexData(req);
self.setupIndexSeoData(req);
};

const superBeforeShow = self.beforeShow;
Expand All @@ -244,6 +275,9 @@ module.exports = {
setupIndexData(req) {
return runSetupIndexData(self, req);
},
setupIndexSeoData(req) {
return runSetupIndexSeoData(req);
},
setupShowData(req) {
return runSetupShowData(self, req);
},
Expand Down
1 change: 1 addition & 0 deletions website/modules/case-studies-page/services/UrlService.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class UrlService {

reqCopy.data.backUrl = UrlService.buildCaseStudyUrl('/cases', queryParams);
reqCopy.data.query = queryParams;
reqCopy.data.hasQueryParams = Object.keys(req.query || {}).length > 0;
}
}

Expand Down
5 changes: 5 additions & 0 deletions website/modules/case-studies-page/views/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{# modules/case-studies-page/views/index.html #}
{% extends "layout.html" %}
{% import '@apostrophecms/pager:macros.html' as pager with context %}
{% block extraHead %}
{{ super() }}
<link rel="canonical" href="{{ data.caseListingSeo.canonicalUrl | e }}" />
<meta name="robots" content="{{ data.caseListingSeo.robots | e }}" />
{% endblock %}
{% block main %}
<div
class="cs_container"
Expand Down
11 changes: 10 additions & 1 deletion website/modules/case-studies-page/views/show.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{% extends "layout.html" %} {% block main %}
{% extends "layout.html" %}
{% block extraHead %}
{{ super() }}
<link rel="canonical" href="{{ data.piece._url | e }}" />
<meta
name="robots"
content="{% if data.hasQueryParams %}noindex,follow{% else %}index,follow{% endif %}"
/>
{% endblock %}
{% block main %}

<div>
<div class="cs_nav-container">
Expand Down
35 changes: 35 additions & 0 deletions website/modules/robots/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
routes(self) {
return {
get: {
'/robots.txt': (req, res) => {
const baseUrl = self.apos.baseUrl || '';
let baseHost = '';
try {
baseHost = new URL(baseUrl).hostname;
} catch (error) {
self.apos.util.warn('Invalid baseUrl for robots.txt route', error);
baseHost = '';
}
const isProduction = process.env.NODE_ENV === 'production';
const productionHosts = [
'speedandfunction.com',
'www.speedandfunction.com',
];
const isProductionHost = productionHosts.includes(baseHost);
const parsedBaseUrl = new URL(baseUrl);
const normalizedBaseUrl = parsedBaseUrl.origin;
if (!isProduction || !isProductionHost) {
return res.type('text/plain').send('User-agent: *\nDisallow: /\n');
}

const robotsContent =
'User-agent: *\n' +
'Allow: /\n\n' +
`Sitemap: ${normalizedBaseUrl}/sitemap.xml\n`;
return res.type('text/plain').send(robotsContent);
},
},
};
},
};
10 changes: 10 additions & 0 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@apostrophecms/form": "^1.4.2",
"@apostrophecms/import-export": "^3.2.0",
"@apostrophecms/security-headers": "^1.0.2",
"@apostrophecms/sitemap": "^1.2.0",
"@barba/core": "^2.10.3",
"abort-controller": "^3.0.0",
"apostrophe": "^4.17.0",
Expand Down
Loading