Skip to content

Commit

Permalink
Build: Remove dependency on grunt-wordpress
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Krinkle committed Nov 12, 2023
1 parent 8290d06 commit d2f2afc
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 74 deletions.
7 changes: 2 additions & 5 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
Copyright jQuery Foundation and other contributors, https://jquery.org/

This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/jquery/grunt-jquery-content
Copyright jQuery Foundation and other contributors, https://github.com/jquery/grunt-jquery-content
Copyright Scott González, http://scottgonzalez.com

The following license applies to all parts of this software except as
documented below:
Expand Down
208 changes: 159 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,111 @@

# grunt-jquery-content

A collection of tasks for building the jQuery web sites via Grunt.
A collection of Grunt tasks for deploying jQuery documentation sites.

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).
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).

## Tasks
## Getting started

### clean-dist
Prerequisites:

This task removes all files in the `dist/` directory.
* Install the gilded-wordpress.php plugin on your WordPress site (copy from [Gilded WordPress](https://github.com/scottgonzalez/gilded-wordpress)).
* 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.

### lint
Basic set up for your project:

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:
1. add `wordpress` configuration to Gruntfile.js.
2. add `build-posts` task configuration to Gruntfile.js.
3. add `grunt.registerTask( "build", [ "build-posts" ] );` to Gruntfile.js

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

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

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:
* `wordpress-deploy`
* `build-wordpress`
* `check-modules`
* `lint` (empty placeholder by default)
* `clean-dist`
* `build` (undefined by default)
* `wordpress-publish`
* `wordpress-validate`
* `wordpress-sync`

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

### build-posts
* lint:
* `xmllint`
* build:
* `build-posts`
* `build-resources`
* `build-xml-entries`
* `build-xml-categories`
* `build-xml-full`

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.
## Config

See the [`postPreprocessors` export](#postpreprocessors) for a hook to implement custom processing.
```javascript
grunt.initConfig({
wordpress: {
url: "wordpress.localhost",
username: "admin",
password: "admin",
dir: "dist"
}
});
```

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

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

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

* `noHeadingLinks`: When set to `false`, heading links won't be generated.
* `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.
This task removes all files in the `dist/` directory.

#### @partial
### lint

Usage:
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:

```html
<pre><code data-linenum>@partial(resources/code-sample.html)</code></pre>
```javascript
grunt.registerTask( "lint", [ "xmllint" ] );
```

Where `resources/code-sample.html` is a relative path in the current directory. That html file will be inserted, escaped and highlighted.

#### @placeholder

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.

Usage:
### build-posts

```html
regular markup will show up here
<!-- @placeholder-start(more markup) -->
this will be replaced
<!-- @placeholder-end -->
other content
```javascript
grunt.initConfig({
"build-posts": {
page: "pages/**"
},
});
```

That will result in:
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.

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

### build-resources

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

```javascript
grunt.initConfig({
"build-resources": {
all: "resources/**"
},
});
```

### xmllint

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

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

### wordpress-validate

Walks through the `wordpress.dir` directory and performs various validations, such as:

* Verifying that XML-RPC is enabled for the WordPress site.
* Verifying that the custom XML-RPC methods for gilded-wordpress are installed.
* Verifying the taxonomies and terms in `taxonomies.json`.
* Verifying that child-parent relationships for posts are valid.
* Verifying data for each post.

### wordpress-sync

Synchronizes everything in `wordpress.dir` to the WordPress site.
This will create/edit/delete terms, posts, and resources.

*Note: `wordpress-validate` must run prior to `wordpress-sync`.*

### wordpress-publish

Alias task for `wordpress-validate` and `wordpress-sync`.
This is useful if your original source content is already in the proper format,
or if you want to manually verify generated content between your custom build and publishing.

### wordpress-deploy

Alias task for `build-wordpress` and `wordpress-publish`.
This is useful if you are generating content for use with `wordpress-sync`.
Simply create a `build-wordpress` task that populates the `wordpress.dir` directory
and your deployments will be as simple as `grunt wordpress-deploy`.

### deploy

Alias task for `wordpress-deploy`.

Since most projects that use grunt-jquery-content have one deploy target (WordPress),
there is a built-in `deploy` task that just runs `wordpress-deploy`.

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.

## Page content

The following features are available in pages built via the `build-posts` task.

### Markdown

Using markdown files provides additional features over HTML files. By default, links for each header are automatically generated for markdown files.

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

* `noHeadingLinks`: When set to `false`, heading links won't be generated.
* `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.

### `@partial`

Usage:

```html
<pre><code data-linenum>@partial(resources/code-sample.html)</code></pre>
```

Where `resources/code-sample.html` is a relative path in the current directory. That html file will be inserted, escaped and highlighted.

### `@placeholder`

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.

Usage:

```html
regular markup will show up here
<!-- @placeholder-start(more markup) -->
this will be replaced
<!-- @placeholder-end -->
other content
```

That will result in:

```html
regular markup will show up here
<!-- more markup -->
other content
```

## Exports

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

### syntaxHighlight( content )
### `syntaxHighlight( content )`

Syntax highlights content.

* `content` String: The string the highlight.

### postPreprocessors
### `postPreprocessors`

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

Expand Down
18 changes: 1 addition & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"async": "^3.2.0",
"cheerio": "^1.0.0-rc.12",
"grunt-check-modules": "^1.1.0",
"grunt-wordpress": "2.1.4",
"gilded-wordpress": "1.0.6",
"he": "^1.2.0",
"highlight.js": "^10.7.2",
"marked": "^4.0.0",
Expand Down
3 changes: 1 addition & 2 deletions tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
module.exports = function( grunt ) {

const fs = require( "fs" );
const wordpress = require( "grunt-wordpress" );
const wordpress = require( "gilded-wordpress" );
const util = require( "../lib/util" );
const syntaxHighlight = require( "../lib/highlight" );
const mainExports = require( "../" );

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

grunt.registerTask( "clean-dist", function() {
Expand Down
41 changes: 41 additions & 0 deletions tasks/wordpress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"use strict";

const wordpress = require( "gilded-wordpress" );

module.exports = function( grunt ) {

var client = ( function() {
var _client;

return function() {
if ( !_client ) {
var config = grunt.config( "wordpress" );
config.verbose = grunt.option( "verbose" ) || false;

_client = wordpress.createClient( config );
_client.log = function() {
grunt.log.writeln.apply( grunt.log, arguments );
};
_client.logError = function() {
grunt.log.error.apply( grunt.log, arguments );
};
}

return _client;
};
} )();

grunt.registerTask( "wordpress-validate", function() {
client().validate( this.async() );
} );

grunt.registerTask( "wordpress-sync", function() {
this.requires( "wordpress-validate" );
client().sync( this.async() );
} );

grunt.registerTask( "wordpress-publish", [ "wordpress-validate", "wordpress-sync" ] );
grunt.registerTask( "wordpress-deploy", [ "build-wordpress", "wordpress-publish" ] );
grunt.registerTask( "deploy", [ "wordpress-deploy" ] );

};

0 comments on commit d2f2afc

Please sign in to comment.