diff --git a/LICENSE.txt b/LICENSE.txt index af932fa..1f0face 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -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: diff --git a/README.md b/README.md index 113eb55..6ecd675 100644 --- a/README.md +++ b/README.md @@ -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 -
@partial(resources/code-sample.html)
+```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 - -this will be replaced - -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 - -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. @@ -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 +
@partial(resources/code-sample.html)
+``` + +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 + +this will be replaced + +other content +``` + +That will result in: + +```html +regular markup will show up here + +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. diff --git a/package-lock.json b/package-lock.json index 5b59d67..5619967 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,8 @@ "dependencies": { "async": "^3.2.0", "cheerio": "^1.0.0-rc.12", + "gilded-wordpress": "1.0.6", "grunt-check-modules": "^1.1.0", - "grunt-wordpress": "2.1.4", "he": "^1.2.0", "highlight.js": "^10.7.2", "marked": "^4.0.0", @@ -1178,14 +1178,6 @@ "node": ">=10" } }, - "node_modules/grunt-wordpress": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/grunt-wordpress/-/grunt-wordpress-2.1.4.tgz", - "integrity": "sha512-6rGpy8qm231FGbLdIylD+3nEpDLRUtJ3DSVaoYHimj388fwVWuLMnYZ7PkoYVa4tJnHkP+Tj0SuMRP5v0baYrQ==", - "dependencies": { - "gilded-wordpress": "1.0.6" - } - }, "node_modules/grunt/node_modules/glob": { "version": "7.1.7", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", @@ -3272,14 +3264,6 @@ "which": "~2.0.2" } }, - "grunt-wordpress": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/grunt-wordpress/-/grunt-wordpress-2.1.4.tgz", - "integrity": "sha512-6rGpy8qm231FGbLdIylD+3nEpDLRUtJ3DSVaoYHimj388fwVWuLMnYZ7PkoYVa4tJnHkP+Tj0SuMRP5v0baYrQ==", - "requires": { - "gilded-wordpress": "1.0.6" - } - }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", diff --git a/package.json b/package.json index 9c22e98..2068b03 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tasks/build.js b/tasks/build.js index 767c326..e960fa4 100644 --- a/tasks/build.js +++ b/tasks/build.js @@ -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() { diff --git a/tasks/wordpress.js b/tasks/wordpress.js new file mode 100644 index 0000000..b79ced8 --- /dev/null +++ b/tasks/wordpress.js @@ -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" ] ); + +};