Skip to content

Commit d2f2afc

Browse files
committedNov 12, 2023
Build: Remove dependency on grunt-wordpress
This 20-line grunt plugin is a very thin wrapper around gilded-wordpress and node-wordpress. For ease of maintenance, use these directly here. None of scripts and other code is copied from the grunt-wordpress repository, only the grunt task itself. Reformatted per current jQuery code conventions to satisfy the ESLint preset. Ref jquery/api.jquery.com#1119
1 parent 8290d06 commit d2f2afc

File tree

6 files changed

+205
-74
lines changed

6 files changed

+205
-74
lines changed
 

‎LICENSE.txt

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
Copyright jQuery Foundation and other contributors, https://jquery.org/
2-
3-
This software consists of voluntary contributions made by many
4-
individuals. For exact contribution history, see the revision history
5-
available at https://github.com/jquery/grunt-jquery-content
1+
Copyright jQuery Foundation and other contributors, https://github.com/jquery/grunt-jquery-content
2+
Copyright Scott González, http://scottgonzalez.com
63

74
The following license applies to all parts of this software except as
85
documented below:

‎README.md

+159-49
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,111 @@
22

33
# grunt-jquery-content
44

5-
A collection of tasks for building the jQuery web sites via Grunt.
5+
A collection of Grunt tasks for deploying jQuery documentation sites.
66

7-
This module builds on top of [grunt-wordpress](https://github.com/scottgonzalez/grunt-wordpress), which builds on top of [Gilded WordPress](https://github.com/scottgonzalez/gilded-wordpress). See the Gilded WordPress documentation for details on the [directory structure and file formats](https://github.com/scottgonzalez/gilded-wordpress#directory-structure).
7+
This module builds on top of [node-wordpress](https://github.com/scottgonzalez/node-wordpress) and the [Gilded WordPress](https://github.com/scottgonzalez/gilded-wordpress) plugin. See the Gilded WordPress documentation for details on the [directory structure and file formats](https://github.com/scottgonzalez/gilded-wordpress#directory-structure).
88

9-
## Tasks
9+
## Getting started
1010

11-
### clean-dist
11+
Prerequisites:
1212

13-
This task removes all files in the `dist/` directory.
13+
* Install the gilded-wordpress.php plugin on your WordPress site (copy from [Gilded WordPress](https://github.com/scottgonzalez/gilded-wordpress)).
14+
* Depending on what kind of files you want to upload as "resources", you may need to configure WordPress to allow more permissive uploads. See the [Gilded WordPress documentation](https://github.com/scottgonzalez/gilded-wordpress#permissive-uploads) for how to do this.
1415

15-
### lint
16+
Basic set up for your project:
1617

17-
This is an empty task list. If the site contains any lint checks, they should be defined here. For example, API sites should have the following task list:
18+
1. add `wordpress` configuration to Gruntfile.js.
19+
2. add `build-posts` task configuration to Gruntfile.js.
20+
3. add `grunt.registerTask( "build", [ "build-posts" ] );` to Gruntfile.js
1821

19-
```
20-
grunt.registerTask( "lint", [ "xmllint" ] );
21-
```
22+
You can now use `grunt wordpress-deploy` to build and deploy your project.
2223

23-
### build
24+
The `wordpress-deploy` task is a tree of the following tasks:
2425

25-
This is a task list that must be defined per site, containing all of the build steps. A simple site would have the following task list:
26+
* `wordpress-deploy`
27+
* `build-wordpress`
28+
* `check-modules`
29+
* `lint` (empty placeholder by default)
30+
* `clean-dist`
31+
* `build` (undefined by default)
32+
* `wordpress-publish`
33+
* `wordpress-validate`
34+
* `wordpress-sync`
2635

27-
```
28-
grunt.registerTask( "build", [ "build-posts", "build-resources" ] );
29-
```
36+
The following optional tasks are made available to use via the `lint` or `build` phase:
3037

31-
### build-posts
38+
* lint:
39+
* `xmllint`
40+
* build:
41+
* `build-posts`
42+
* `build-resources`
43+
* `build-xml-entries`
44+
* `build-xml-categories`
45+
* `build-xml-full`
3246

33-
This multi-task takes a list of html or markdown files, copies them to `[wordpress.dir]/posts/[post-type]/`, processes `@partial` entries and highlights the syntax in each. The keys are the post types for each set of posts.
47+
## Config
3448

35-
See the [`postPreprocessors` export](#postpreprocessors) for a hook to implement custom processing.
49+
```javascript
50+
grunt.initConfig({
51+
wordpress: {
52+
url: "wordpress.localhost",
53+
username: "admin",
54+
password: "admin",
55+
dir: "dist"
56+
}
57+
});
58+
```
3659

37-
#### markdown
60+
* `url`: The URL for the WordPress install.
61+
Can be a full URL, e.g., `http://wordpress.localhost:1234/some/path`
62+
or as short as just the host name.
63+
If the protocol is `https`, then a secure connection will be used.
64+
* `host` (optional): The actual host to connect to if different from the URL, e.g., when deploying to a local server behind a firewall.
65+
* `username`: WordPress username.
66+
* `password`: WordPress password.
67+
* `dir`: Directory containing posts, taxonomies, and resources.
68+
* See the [Gilded WordPress documentation](https://github.com/scottgonzalez/gilded-wordpress#directory-structure) for details on the directory structure and file formats.
3869

39-
Using markdown files provides additional features over HTML files. By default, links for each header are automatically generated for markdown files.
70+
## Tasks
4071

41-
In addition to the [standard metadata](https://github.com/scottgonzalez/gilded-wordpress#post-files) for post files, the following properties can be set:
72+
### clean-dist
4273

43-
* `noHeadingLinks`: When set to `false`, heading links won't be generated.
44-
* `toc`: When set to `true`, a table of contents will be inserted at the top of the post based on the headings within the post.
74+
This task removes all files in the `dist/` directory.
4575

46-
#### @partial
76+
### lint
4777

48-
Usage:
78+
This is an empty task list by default. If the site contains any lint checks, they should be defined here. For example, API documentation sites should have the following task list:
4979

50-
```html
51-
<pre><code data-linenum>@partial(resources/code-sample.html)</code></pre>
80+
```javascript
81+
grunt.registerTask( "lint", [ "xmllint" ] );
5282
```
5383

54-
Where `resources/code-sample.html` is a relative path in the current directory. That html file will be inserted, escaped and highlighted.
55-
56-
#### @placeholder
57-
58-
Inside markup included with `@partial`, you can mark sections of code as `@placeholder` code, to be excluded from the inserted code, replaced with an html comment.
59-
60-
Usage:
84+
### build-posts
6185

62-
```html
63-
regular markup will show up here
64-
<!-- @placeholder-start(more markup) -->
65-
this will be replaced
66-
<!-- @placeholder-end -->
67-
other content
86+
```javascript
87+
grunt.initConfig({
88+
"build-posts": {
89+
page: "pages/**"
90+
},
91+
});
6892
```
6993

70-
That will result in:
94+
This multi-task takes a list of html or markdown files, copies them to `[wordpress.dir]/posts/[post-type]/`, processes `@partial` entries and highlights the syntax in each. The keys are the post types for each set of posts.
7195

72-
```html
73-
regular markup will show up here
74-
<!-- more markup -->
75-
other content
76-
```
96+
See the [`postPreprocessors` export](#postpreprocessors) for a hook to implement custom processing.
7797

7898
### build-resources
7999

80100
This mult-task copies all source files into `[wordpress.dir]/resources/`.
81101

102+
```javascript
103+
grunt.initConfig({
104+
"build-resources": {
105+
all: "resources/**"
106+
},
107+
});
108+
```
109+
82110
### xmllint
83111

84112
This multi-task lints XML files to ensure the files are valid.
@@ -114,19 +142,101 @@ Code examples in the descriptions will be syntax highlighted.
114142

115143
This task generates a single XML file that contains all entries and stores the result in `[wordpress.dir]/resources/api.xml`.
116144

145+
### wordpress-validate
146+
147+
Walks through the `wordpress.dir` directory and performs various validations, such as:
148+
149+
* Verifying that XML-RPC is enabled for the WordPress site.
150+
* Verifying that the custom XML-RPC methods for gilded-wordpress are installed.
151+
* Verifying the taxonomies and terms in `taxonomies.json`.
152+
* Verifying that child-parent relationships for posts are valid.
153+
* Verifying data for each post.
117154

155+
### wordpress-sync
156+
157+
Synchronizes everything in `wordpress.dir` to the WordPress site.
158+
This will create/edit/delete terms, posts, and resources.
159+
160+
*Note: `wordpress-validate` must run prior to `wordpress-sync`.*
161+
162+
### wordpress-publish
163+
164+
Alias task for `wordpress-validate` and `wordpress-sync`.
165+
This is useful if your original source content is already in the proper format,
166+
or if you want to manually verify generated content between your custom build and publishing.
167+
168+
### wordpress-deploy
169+
170+
Alias task for `build-wordpress` and `wordpress-publish`.
171+
This is useful if you are generating content for use with `wordpress-sync`.
172+
Simply create a `build-wordpress` task that populates the `wordpress.dir` directory
173+
and your deployments will be as simple as `grunt wordpress-deploy`.
174+
175+
### deploy
176+
177+
Alias task for `wordpress-deploy`.
178+
179+
Since most projects that use grunt-jquery-content have one deploy target (WordPress),
180+
there is a built-in `deploy` task that just runs `wordpress-deploy`.
181+
182+
If your project has other deploy targets, you can redefine `deploy` as an alias that runs both `wordpress-deploy` and your other deployment-related tasks.
183+
184+
## Page content
185+
186+
The following features are available in pages built via the `build-posts` task.
187+
188+
### Markdown
189+
190+
Using markdown files provides additional features over HTML files. By default, links for each header are automatically generated for markdown files.
191+
192+
In addition to the [standard metadata](https://github.com/scottgonzalez/gilded-wordpress#post-files) for post files, the following properties can be set:
193+
194+
* `noHeadingLinks`: When set to `false`, heading links won't be generated.
195+
* `toc`: When set to `true`, a table of contents will be inserted at the top of the post based on the headings within the post.
196+
197+
### `@partial`
198+
199+
Usage:
200+
201+
```html
202+
<pre><code data-linenum>@partial(resources/code-sample.html)</code></pre>
203+
```
204+
205+
Where `resources/code-sample.html` is a relative path in the current directory. That html file will be inserted, escaped and highlighted.
206+
207+
### `@placeholder`
208+
209+
Inside markup included with `@partial`, you can mark sections of code as `@placeholder` code, to be excluded from the inserted code, replaced with an html comment.
210+
211+
Usage:
212+
213+
```html
214+
regular markup will show up here
215+
<!-- @placeholder-start(more markup) -->
216+
this will be replaced
217+
<!-- @placeholder-end -->
218+
other content
219+
```
220+
221+
That will result in:
222+
223+
```html
224+
regular markup will show up here
225+
<!-- more markup -->
226+
other content
227+
```
118228

119229
## Exports
120230

121-
This module also exports some methods through the standard node `require()` API.
231+
The grunt-jquery-content module primarily registers Grunt tasks, but it also exports some methods through the `require()` API.
122232

123-
### syntaxHighlight( content )
233+
### `syntaxHighlight( content )`
124234

125235
Syntax highlights content.
126236

127237
* `content` String: The string the highlight.
128238

129-
### postPreprocessors
239+
### `postPreprocessors`
130240

131241
Hooks for modifying the posts before they're processed in the [`build-posts`](#build-posts) task.
132242

‎package-lock.json

+1-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"async": "^3.2.0",
2424
"cheerio": "^1.0.0-rc.12",
2525
"grunt-check-modules": "^1.1.0",
26-
"grunt-wordpress": "2.1.4",
26+
"gilded-wordpress": "1.0.6",
2727
"he": "^1.2.0",
2828
"highlight.js": "^10.7.2",
2929
"marked": "^4.0.0",

‎tasks/build.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
module.exports = function( grunt ) {
44

55
const fs = require( "fs" );
6-
const wordpress = require( "grunt-wordpress" );
6+
const wordpress = require( "gilded-wordpress" );
77
const util = require( "../lib/util" );
88
const syntaxHighlight = require( "../lib/highlight" );
99
const mainExports = require( "../" );
1010

1111
// Load external tasks as local tasks
1212
// Grunt doesn't provide an API to pass thru tasks from dependent grunt plugins
13-
require( "grunt-wordpress/tasks/wordpress" )( grunt );
1413
require( "grunt-check-modules/tasks/check-modules" )( grunt );
1514

1615
grunt.registerTask( "clean-dist", function() {

‎tasks/wordpress.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"use strict";
2+
3+
const wordpress = require( "gilded-wordpress" );
4+
5+
module.exports = function( grunt ) {
6+
7+
var client = ( function() {
8+
var _client;
9+
10+
return function() {
11+
if ( !_client ) {
12+
var config = grunt.config( "wordpress" );
13+
config.verbose = grunt.option( "verbose" ) || false;
14+
15+
_client = wordpress.createClient( config );
16+
_client.log = function() {
17+
grunt.log.writeln.apply( grunt.log, arguments );
18+
};
19+
_client.logError = function() {
20+
grunt.log.error.apply( grunt.log, arguments );
21+
};
22+
}
23+
24+
return _client;
25+
};
26+
} )();
27+
28+
grunt.registerTask( "wordpress-validate", function() {
29+
client().validate( this.async() );
30+
} );
31+
32+
grunt.registerTask( "wordpress-sync", function() {
33+
this.requires( "wordpress-validate" );
34+
client().sync( this.async() );
35+
} );
36+
37+
grunt.registerTask( "wordpress-publish", [ "wordpress-validate", "wordpress-sync" ] );
38+
grunt.registerTask( "wordpress-deploy", [ "build-wordpress", "wordpress-publish" ] );
39+
grunt.registerTask( "deploy", [ "wordpress-deploy" ] );
40+
41+
};

0 commit comments

Comments
 (0)
Please sign in to comment.