Skip to content

Commit ffbdc46

Browse files
committed
Adds --within date to WordPress REST API calls (mega speed boost)
1 parent 2e95cb7 commit ffbdc46

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/DataSource/WordPressApi.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "dotenv/config"
2+
import { DateCompare } from "@11ty/eleventy-utils";
23

34
import { DataSource } from "../DataSource.js";
45
import { HostedWordPressApi } from "./HostedWordPressApi.js"
@@ -56,14 +57,21 @@ class WordPressApi extends DataSource {
5657
// status=publish,future,draft,pending,private
5758
// status=any
5859

60+
let withinStr = "";
61+
if(this.within) {
62+
let ms = DateCompare.getDurationMs(this.within);
63+
let d = this.toIsoDate(new Date(Date.now() - ms));
64+
withinStr = `&after=${d}&modified_after=${d}`
65+
}
66+
5967
let statusStr = "";
6068
// Only request Drafts if auth’d
6169
if(process.env.WORDPRESS_USERNAME && process.env.WORDPRESS_PASSWORD) {
6270
// Commas are encoded
6371
statusStr = `&status=${encodeURIComponent("publish,draft")}`;
6472
}
6573

66-
return this.#getSubtypeUrl("posts", `?page=${pageNumber}&per_page=100${statusStr}`);
74+
return this.#getSubtypeUrl("posts", `?page=${pageNumber}&per_page=100${statusStr}${withinStr}`);
6775
};
6876
}
6977

0 commit comments

Comments
 (0)