Skip to content
Draft
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 modules/@apostrophecms/asset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ module.exports = {
process.env.HEROKU_RELEASE_VERSION ||
process.env.PLATFORM_TREE_ID;
if (viaEnv) {
console.log('===>', viaEnv);
return viaEnv;
}
try {
Expand Down Expand Up @@ -1164,6 +1165,7 @@ module.exports = {
// Return the URL of the asset with the given path, taking into account
// the release id, uploadfs, etc.
url(path) {
console.log(`${process.pid} here we go for ${path}`);
return `${self.getAssetBaseUrl()}${path}`;
},
devServerUrl(path) {
Expand Down
57 changes: 56 additions & 1 deletion modules/@apostrophecms/doc-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@
}
await self.apos.schema.indexFields(self.schema, doc, texts);
}
}
},

Check failure on line 397 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 6)

Unexpected trailing comma

Check failure on line 397 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 8)

Unexpected trailing comma

Check failure on line 397 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6)

Unexpected trailing comma

Check failure on line 397 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 7)

Unexpected trailing comma

Check failure on line 397 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 8)

Unexpected trailing comma

Check failure on line 397 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 7)

Unexpected trailing comma

};
},
Expand Down Expand Up @@ -1648,7 +1648,62 @@
name: key,
...self.columns[key]
}));
},


Check failure on line 1653 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 6)

More than 1 blank line not allowed

Check failure on line 1653 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 8)

More than 1 blank line not allowed

Check failure on line 1653 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6)

More than 1 blank line not allowed

Check failure on line 1653 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 7)

More than 1 blank line not allowed

Check failure on line 1653 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 8)

More than 1 blank line not allowed

Check failure on line 1653 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 7)

More than 1 blank line not allowed
async getAllUrlMetadata(req) {
const results = [];
let skip = 0;
// Declared here so we can use do/while
let docs = null;

do {
// Paginate through 100 at a time to avoid exhausting
// memory
docs = await self.getUrlMetadataQuery(req)
.skip(skip).limit(100).toArray();
await Promise.all(docs.map(async doc => {
results.push(...await self.getUrlMetadata(req, doc));
}));
skip += docs.length;
} while (docs.length > 0);

return results;
},

Check failure on line 1672 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 6)

Trailing spaces not allowed

Check failure on line 1672 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 8)

Trailing spaces not allowed

Check failure on line 1672 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6)

Trailing spaces not allowed

Check failure on line 1672 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 7)

Trailing spaces not allowed

Check failure on line 1672 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 8)

Trailing spaces not allowed

Check failure on line 1672 in modules/@apostrophecms/doc-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 7)

Trailing spaces not allowed

// Used to build sitemaps and assist in static site builds. Extend to
// return all URLs that provide views of this document and
// should be included in sitemaps and static builds. You may
// use `async` when extending
getUrlMetadata(req, piece) {
if (!piece._url) {
return [];
}
return [
{
url: piece._url,
type: piece.type,
aposDocId: piece.aposDocId,
i18nId: piece.aposDocId,
_id: piece._id,
// For legacy reasons. Google 100% ignores this
changefreq: 'daily',
// For legacy reasons. Google 100% ignores this
priority: 1.0
}
];
},

// Extend to change the query used when fetching documents of this type
// for purposes of building sitemaps and static sites. Should be efficient
// while still capturing enough information to generate all URLs for
// this particular type of document. By default no relationships are fetched
// and widget loaders for areas are not run
getUrlMetadataQuery(req) {
return self.find(req, {})
.relationships(false).areas(false);
}

};
},
extendMethods(self) {
Expand Down
1 change: 1 addition & 0 deletions modules/@apostrophecms/express/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ module.exports = {

// awaitable listen function
function listen() {
console.log('--->', process.env);
if (address !== false) {
self.server = self.apos.baseApp.listen(port, address);
} else if (port) {
Expand Down
7 changes: 6 additions & 1 deletion modules/@apostrophecms/page-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ module.exports = {
'slug'
]);
self.rules = {};
self.dispatchAll();
self.composeFilters();
self.composeColumns();
},
handlers(self) {
return {
'apostrophe:modulesRegistered': {
dispatchAll() {
// Late enough that all subclasses have contributed things to self
self.dispatchAll();
}
},
'@apostrophecms/page:serve': {
async dispatchPage(req) {
if (!req.data.bestPage) {
Expand Down
80 changes: 77 additions & 3 deletions modules/@apostrophecms/piece-page-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//
// ### `piecesFilters`
//
// If present, this is an array of objects with `name` properties.This works
// If present, this is an array of objects with `name` properties. This works
// only if the corresponding query builders exist and have a `launder` method.
// An array of choices for each is populated in `req.data.piecesFilters`. The
// choices in the array are objects with `label` and `value` properties.
Expand All @@ -37,6 +37,7 @@
self.piecesCssName = self.apos.util.cssName(self.pieces.name);

self.piecesFilters = self.options.piecesFilters || [];
console.log(`>> ${self.__meta.name}`);

self.enableAddUrlsToPieces();
},
Expand Down Expand Up @@ -199,6 +200,26 @@

dispatchAll() {
self.dispatch('/', self.indexPage);
if (self.apos.url.options.static) {
self.dispatch(`/page/:page`, req => {

Check warning on line 204 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 6)

Strings must use singlequote

Check warning on line 204 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 8)

Strings must use singlequote

Check warning on line 204 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6)

Strings must use singlequote

Check warning on line 204 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 7)

Strings must use singlequote

Check warning on line 204 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 8)

Strings must use singlequote

Check warning on line 204 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 7)

Strings must use singlequote
req.query.page = req.params.page;
return self.indexPage(req);
});
console.log(self.options.piecesFilters);
console.log(`** ${self.__meta.name}`);
console.log(self.piecesFilters);
for (const filter of self.piecesFilters) {
self.dispatch(`/${filter.name}/:filterValue`, req => {
req.query[filter.name] = req.params.filterValue;
return self.indexPage(req);
});
self.dispatch(`/${filter.name}/:filterValue/page/:page`, req => {
req.query[filter.name] = req.params.filterValue;
req.query.page = req.params.page;
return self.indexPage(req);
});
}
}
self.dispatch('/:slug', self.showPage);
},

Expand Down Expand Up @@ -340,15 +361,38 @@

async populatePiecesFilters(query) {
const req = query.req;
req.data.piecesFilters = req.data.piecesFilters || {};
const filtersWithChoices = await self.getFiltersWithChoices(query);
req.data.filters = filtersWithChoices;
// for bc (less useful)
req.data.piecesFilters = {};
for (const filter of filtersWithChoices) {
req.data.piecesFilters[filter.name] = filter.choices;
}
},

async getFiltersWithChoices(query, { allCounts = false } = {}) {
const results = [];
for (const filter of self.piecesFilters) {
// The choices for each filter should reflect the effect of all
// filters except this one (filtering by topic pares down the list of
// categories and vice versa)
const _query = query.clone();
_query[filter.name](undefined);
req.data.piecesFilters[filter.name] = await _query.toChoices(filter.name, _.pick(filter, 'counts'));
const choices = await _query.toChoices(filter.name, allCounts || _.pick(filter, 'counts'));
console.log(query.req.params, filter.name);
for (const choice of choices) {
choice._url = query.req.data.page._url + self.apos.url.getChoiceFilter(filter.name, choice.value, 1);

Check warning on line 384 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 6)

This line has a length of 113. Maximum allowed is 90

Check warning on line 384 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 8)

This line has a length of 113. Maximum allowed is 90

Check warning on line 384 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6)

This line has a length of 113. Maximum allowed is 90

Check warning on line 384 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 7)

This line has a length of 113. Maximum allowed is 90

Check warning on line 384 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 8)

This line has a length of 113. Maximum allowed is 90

Check warning on line 384 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 7)

This line has a length of 113. Maximum allowed is 90
if (query.req.query[filter.name] === choice.value) {
choice.active = true;
console.log('MATCH');
}
}
results.push({
...filter,
choices
});
}
return results;
}
};

Expand All @@ -368,6 +412,36 @@
} else {
return data;
}
},
async getUrlMetadata(_super, req, page) {
const metadata = _super(req, page);
if (!metadata.length) {
return metadata;
}
const query = self.indexQuery(req);
const filters = await self.getFiltersWithChoices(query, { allCounts: true });
for (const filter of filters) {
for (const choice of filter.choices) {
const pages = Math.min(1, Math.ceil(choice.count / self.perPage));
for (let page = 1; (page <= pages); page++) {
metadata.push({
...metadata[0],
i18nId: `${metadata[0].i18nId}.${self.apos.util.slugify(filter.name)}.${self.apos.util.slugify(choice.value)}.${page}`,
_url: metadata[0]._url + self.apos.url.getChoiceFilter(filter.name, choice.value, page)

Check warning on line 430 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 6)

This line has a length of 103. Maximum allowed is 90

Check warning on line 430 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 8)

This line has a length of 103. Maximum allowed is 90

Check warning on line 430 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6)

This line has a length of 103. Maximum allowed is 90

Check warning on line 430 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 7)

This line has a length of 103. Maximum allowed is 90

Check warning on line 430 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 8)

This line has a length of 103. Maximum allowed is 90

Check warning on line 430 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 7)

This line has a length of 103. Maximum allowed is 90
});
}
}
}
await query.toCount();
const pages = query.get('totalPages');
for (let page = 2; (2 <= pages); page++) {

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 6)

'pages' is not modified in this loop

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 6)

Expected literal to be on the right side of <=

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 8)

'pages' is not modified in this loop

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 8)

Expected literal to be on the right side of <=

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6)

'pages' is not modified in this loop

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6)

Expected literal to be on the right side of <=

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 7)

'pages' is not modified in this loop

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 7)

Expected literal to be on the right side of <=

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 8)

'pages' is not modified in this loop

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (22, 8)

Expected literal to be on the right side of <=

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 7)

'pages' is not modified in this loop

Check failure on line 437 in modules/@apostrophecms/piece-page-type/index.js

View workflow job for this annotation

GitHub Actions / build (20, 7)

Expected literal to be on the right side of <=
metadata.push({
...metadata[0],
i18nId: `${metadata[0].i18nId}.${page}`,
_url: metadata[0]._url + self.apos.url.getPageFilter(page)
});
}
return metadata;
}
};
}
Expand Down
3 changes: 3 additions & 0 deletions modules/@apostrophecms/template/views/outerLayoutBase.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<!DOCTYPE html>
<html lang="{% block locale %}{{ data.locale }}{% endblock %}" {% block extraHtml %}{% endblock %}>
<head>
{% block encoding %}
<meta charset="utf-8">
{% endblock %}
{% block startHead %}
{% endblock %}
{% component '@apostrophecms/template:inject' with { where: 'head', end: 'prepend', when: 'hmr' } %}
Expand Down
Loading
Loading