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
12 changes: 8 additions & 4 deletions wordpress-to-github/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ const pathFromMediaSourceUrl = source_url =>
*
* @param {string} wordpress_source_url
* @param {GitHubTarget} gitHubTarget
* @param {string} object_url
*/
const commonMeta = (wordpress_source_url, gitHubTarget) => ({
const commonMeta = (wordpress_source_url, gitHubTarget, object_url) => ({
api_version: "v2",
api_url: wordpress_source_url + apiPath,
object_url,
process: {
source_code: "https://github.com/cagov/wordpress-to-github",
source_data: wordpress_source_url,
Expand Down Expand Up @@ -295,18 +297,20 @@ const fetchDictionary = async (wordPressApiUrl, listname) =>
* @param {GitHubTarget} gitHubTarget
* @param {string} field_reference //url for field refernce
* @param {GithubOutputJson} data
* @param {string} object_url
*/
const wrapInFileMeta = (
wordpress_source_url,
gitHubTarget,
field_reference,
data
data,
object_url
) => ({
meta: {
created_date: data.date_gmt,
updated_date: data.modified_gmt,
field_reference,
...commonMeta(wordpress_source_url, gitHubTarget)
...commonMeta(wordpress_source_url, gitHubTarget, object_url)
},
data
});
Expand Down Expand Up @@ -455,4 +459,4 @@ module.exports = {
WpApi_getSomething,
pathFromMediaSourceUrl,
addMediaSection
};
};
31 changes: 23 additions & 8 deletions wordpress-to-github/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,21 @@ const SyncEndpoint = async (
}

if (endpointConfig.GeneralFilePath) {
const targetUrl = `${sourceEndpointConfig.WordPressSource.url}/wp-json?_fields=description,gmt_offset,name,namespaces,timezone_string,home,url`;
const fetchResponse = await WpApi_getSomething(
`${
sourceEndpointConfig.WordPressSource.url
}/wp-json/?_fields=description,gmt_offset,name,namespaces,timezone_string,home,url&cachebust=${Math.random()}`
`${targetUrl}&cachebust=${Math.random()}`
);

const data = await fetchResponse.json();
delete data._links;

const jsonData = {
meta: {
...commonMeta(sourceEndpointConfig.WordPressSource.url, gitHubTarget)
...commonMeta(
sourceEndpointConfig.WordPressSource.url,
gitHubTarget,
targetUrl
)
},
data
};
Expand Down Expand Up @@ -244,6 +247,9 @@ const SyncEndpoint = async (
)
};

/** @type {string} */
const object_url = jsonData["_links"]?.self[0].href;

removeExcludedProperties(jsonData, endpointConfig.ExcludeProperties);

if (x.media_details.sizes && Object.keys(x.media_details.sizes).length) {
Expand Down Expand Up @@ -273,7 +279,8 @@ const SyncEndpoint = async (
sourceEndpointConfig.WordPressSource.url,
gitHubTarget,
fieldMetaReference.media,
jsonData
jsonData,
object_url
)
);
});
Expand Down Expand Up @@ -381,6 +388,9 @@ const SyncEndpoint = async (

addMediaSection(endpointConfig, mediaMap, jsonData, HTML);

/** @type {string} */
const object_url = jsonData["_links"]?.self[0].href;

removeExcludedProperties(jsonData, endpointConfig.ExcludeProperties);

const ignoreThisOne = anythingInArrayMatch(
Expand All @@ -396,7 +406,8 @@ const SyncEndpoint = async (
sourceEndpointConfig.WordPressSource.url,
gitHubTarget,
fieldMetaReference.posts,
jsonData
jsonData,
object_url
)
);
postMap.set(`${x.slug}.html`, ignoreThisOne ? null : HTML);
Expand Down Expand Up @@ -431,6 +442,9 @@ const SyncEndpoint = async (

addMediaSection(endpointConfig, mediaMap, jsonData, HTML);

/** @type {string} */
const object_url = jsonData["_links"]?.self[0].href;

removeExcludedProperties(jsonData, endpointConfig.ExcludeProperties);

const ignoreThisOne = anythingInArrayMatch(
Expand All @@ -446,7 +460,8 @@ const SyncEndpoint = async (
sourceEndpointConfig.WordPressSource.url,
gitHubTarget,
fieldMetaReference.media,
jsonData
jsonData,
object_url
)
);
pagesMap.set(`${x.slug}.html`, ignoreThisOne ? null : HTML);
Expand Down Expand Up @@ -478,4 +493,4 @@ const SyncEndpoint = async (

module.exports = {
SyncEndpoint
};
};