2019-02-25 17:55:55 +03:00
|
|
|
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
2023-10-12 22:16:45 +03:00
|
|
|
import {ALL_POST_INCLUDES} from './post';
|
2019-02-25 17:55:55 +03:00
|
|
|
|
2022-02-02 19:57:22 +03:00
|
|
|
export default class Page extends ApplicationAdapter {
|
2023-10-12 22:16:45 +03:00
|
|
|
// posts and pages now include everything except post_revisions by default
|
2019-02-25 17:55:55 +03:00
|
|
|
buildIncludeURL(store, modelName, id, snapshot, requestType, query) {
|
2023-06-16 14:24:02 +03:00
|
|
|
const url = this.buildURL(modelName, id, snapshot, requestType, query);
|
|
|
|
const parsedUrl = new URL(url);
|
|
|
|
|
|
|
|
if (snapshot?.adapterOptions?.saveRevision) {
|
|
|
|
const saveRevision = snapshot.adapterOptions.saveRevision;
|
|
|
|
parsedUrl.searchParams.append('save_revision', saveRevision);
|
|
|
|
}
|
|
|
|
|
2023-08-09 01:44:54 +03:00
|
|
|
if (snapshot?.adapterOptions?.convertToLexical) {
|
|
|
|
const convertToLexical = snapshot.adapterOptions.convertToLexical;
|
|
|
|
parsedUrl.searchParams.append('convert_to_lexical', convertToLexical);
|
|
|
|
}
|
|
|
|
|
2023-10-12 22:16:45 +03:00
|
|
|
// on create/update we need to explicitly request post_revisions to be included
|
|
|
|
// so we can compare and create a new one later if needed but that means we
|
|
|
|
// have to specify every post include option
|
|
|
|
if (requestType === 'createRecord' || requestType === 'updateRecord') {
|
|
|
|
parsedUrl.searchParams.append('include', ALL_POST_INCLUDES);
|
|
|
|
}
|
|
|
|
|
2023-06-16 14:24:02 +03:00
|
|
|
return parsedUrl.toString();
|
2022-02-02 19:57:22 +03:00
|
|
|
}
|
2019-02-25 17:55:55 +03:00
|
|
|
|
2022-09-15 19:40:45 +03:00
|
|
|
buildURL() {
|
|
|
|
const url = super.buildURL(...arguments);
|
|
|
|
|
|
|
|
try {
|
|
|
|
const parsedUrl = new URL(url);
|
|
|
|
if (!parsedUrl.searchParams.get('formats')) {
|
|
|
|
parsedUrl.searchParams.set('formats', 'mobiledoc,lexical');
|
|
|
|
return parsedUrl.href;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// noop, just use the original url
|
|
|
|
console.error('Couldn\'t parse URL', e); // eslint-disable-line
|
2022-09-13 23:01:53 +03:00
|
|
|
}
|
|
|
|
|
2022-09-15 19:40:45 +03:00
|
|
|
return url;
|
2019-02-25 17:55:55 +03:00
|
|
|
}
|
2022-09-16 14:54:43 +03:00
|
|
|
|
|
|
|
// posts and pages now include all relations by default so we don't want
|
|
|
|
// EmbeddedRelationAdapter.buildQuery adding an `?include=` param that
|
|
|
|
// overrides the defaults with a more restrictive list
|
|
|
|
buildQuery(store, modelName, options) {
|
|
|
|
return options;
|
|
|
|
}
|
2022-02-02 19:57:22 +03:00
|
|
|
}
|