diff --git a/components/content/content.jsx b/components/content/content.jsx index b6b015e..513e0fe 100644 --- a/components/content/content.jsx +++ b/components/content/content.jsx @@ -12,7 +12,7 @@ var Loop = require( './loop/loop.jsx' ), /** * Handles getting of posts from the server */ -Content = React.createClass({ +var Content = React.createClass({ componentDidMount: function() { @@ -32,14 +32,16 @@ Content = React.createClass({ entry_thumbnail(); // Scroll to top of page so user can see page transition - window.scroll(0,0); + //window.scroll(0,0); }, render: function() { + var singlePostID; + // Check if we're just viewing one post, if so, pass the ID down if ( this.props.data.length === 1 ) { - singlePostID = this.props.data[0].ID; + singlePostID = this.props.data[0].id; } else { singlePostID = 0; } @@ -51,4 +53,4 @@ Content = React.createClass({ } }); -module.exports = Content; \ No newline at end of file +module.exports = Content; diff --git a/components/content/loop/comments/comment-form/comment-form.jsx b/components/content/loop/comments/comment-form/comment-form.jsx index 4fb4660..3badc21 100644 --- a/components/content/loop/comments/comment-form/comment-form.jsx +++ b/components/content/loop/comments/comment-form/comment-form.jsx @@ -16,7 +16,7 @@ var commentForm = React.createClass({ if ( !text || !author ) { return; } - this.props.onCommentSubmit({comment_author: author, comment_author_email: emailAddress, comment_author_url: website, content: text }); + this.props.onCommentSubmit({author_name: author, author_email: emailAddress, author_url: website, content: text }); this.refs.author.getDOMNode().value = ''; this.refs.emailAddress.getDOMNode().value = ''; this.refs.website.getDOMNode().value = ''; @@ -48,4 +48,4 @@ var commentForm = React.createClass({ }); -module.exports = commentForm; \ No newline at end of file +module.exports = commentForm; diff --git a/components/content/loop/comments/comment-list/comment/comment.jsx b/components/content/loop/comments/comment-list/comment/comment.jsx index 5abf80e..9d9b0de 100644 --- a/components/content/loop/comments/comment-list/comment/comment.jsx +++ b/components/content/loop/comments/comment-list/comment/comment.jsx @@ -23,16 +23,16 @@ var Comment = React.createClass({
-
+
Reply
@@ -43,4 +43,4 @@ var Comment = React.createClass({ }); -module.exports = Comment; \ No newline at end of file +module.exports = Comment; diff --git a/components/content/loop/comments/comments.jsx b/components/content/loop/comments/comments.jsx index 506565b..71498ce 100644 --- a/components/content/loop/comments/comments.jsx +++ b/components/content/loop/comments/comments.jsx @@ -16,7 +16,7 @@ var CommentList = require( './comment-list/comment-list.jsx' ), var Comments = React.createClass({ loadCommentsFromServer: function() { - var repliesLink = '/wp-json/posts/' + this.props.postID + '/comments/'; + var repliesLink = '/wp-json/wp/v2/comments?post=' + this.props.postID; var self = this; @@ -34,7 +34,7 @@ var Comments = React.createClass({ var newComment, self = this, - url = '/wp-json/picard/comments'; + url = '/wp-json/wp/v2/comments?post=' + this.props.postID; request .post( url ) .type( 'form' ) @@ -44,7 +44,7 @@ var Comments = React.createClass({ newComment = JSON.parse( res.text ); self.setState( { data: self.state.data.concat( [ newComment ] ) } ); } else { - console.error( '/wp-json/picard/comments', err.toString() ); + console.error( '/wp-json/wp/v2/comments?post=' + self.props.postID, err.toString() ); } }); @@ -57,7 +57,7 @@ var Comments = React.createClass({ componentDidMount: function() { this.loadCommentsFromServer(); }, - + render: function() { return (
@@ -70,4 +70,4 @@ var Comments = React.createClass({ }); -module.exports = Comments; \ No newline at end of file +module.exports = Comments; diff --git a/components/content/loop/hentry/entry-content/entry-content.jsx b/components/content/loop/hentry/entry-content/entry-content.jsx index 9349c65..4ea8040 100644 --- a/components/content/loop/hentry/entry-content/entry-content.jsx +++ b/components/content/loop/hentry/entry-content/entry-content.jsx @@ -9,11 +9,12 @@ var React = require( 'react' ); var EntryContent = React.createClass({ render: function() { + console.log( this.props.content ); return ( -
+
); } }); -module.exports = EntryContent; \ No newline at end of file +module.exports = EntryContent; diff --git a/components/content/loop/hentry/hentry.jsx b/components/content/loop/hentry/hentry.jsx index f734b60..1c0bb17 100644 --- a/components/content/loop/hentry/hentry.jsx +++ b/components/content/loop/hentry/hentry.jsx @@ -1,8 +1,7 @@ /** * External dependencies */ -var React = require( 'react/addons' ), - page = require( 'page' ); +var React = require( 'react/addons' ); /** * Internal dependencies @@ -18,20 +17,29 @@ var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup; /** * Renders post */ -Hentry = React.createClass({ +var Hentry = React.createClass({ handleAdd: function( e ) { e.preventDefault(); url = this.props.link; url = url.replace(/^.*\/\/[^\/]+/, ''); - page( url ); + //page( url ); }, render: function() { - var d = new Date( this.props.date ), + var entryContent, + d = new Date( this.props.date ), formattedDate = d.toDateString(); + if ( 'the_date' !== this.props.date ) { + d = new Date( this.props.date ); + formattedDate = d.toDateString(); + } else { + formattedDate = this.props.date; + } + // Decide whether or not to render comments and entry-content var comments, content; + console.log( this.props ); if ( this.props.context !== 'index' && this.props.showExtra === true ) { comments = ; entryContent = ; @@ -50,7 +58,7 @@ Hentry = React.createClass({ entryHeader =

- + {this.props.title}

@@ -63,7 +71,7 @@ Hentry = React.createClass({ } else { entryHeader =

- + {this.props.title}

@@ -79,7 +87,7 @@ Hentry = React.createClass({
{ entryHeader } - + { entryContent }
@@ -89,4 +97,4 @@ Hentry = React.createClass({ } }); -module.exports = Hentry; \ No newline at end of file +module.exports = Hentry; diff --git a/components/content/loop/loop.jsx b/components/content/loop/loop.jsx index a10e97d..0eaf3ca 100644 --- a/components/content/loop/loop.jsx +++ b/components/content/loop/loop.jsx @@ -1,8 +1,7 @@ /** * External dependencies */ -var React = require( 'react/addons' ), - page = require( 'page' ); +var React = require( 'react/addons' ); /** * Internal dependencies @@ -15,20 +14,23 @@ var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup; /** * Renders list of posts */ -Loop = React.createClass({ +var Loop = React.createClass({ render: function() { var context = this.props.context, showExtra = false, next, previous; - if ( this.props.postID !== 0 && this.props.postID === this.props.data[0].ID ) { + if ( this.props.postID !== 0 && this.props.postID === this.props.data[0].id ) { showExtra = true; } + var loop; + var postNodes = this.props.data.map( function ( post ) { + loop = post.loop; return ( - + ); }); @@ -42,13 +44,15 @@ Loop = React.createClass({ return (
- + { loop ? 'the_loop' : null } + { postNodes } { navigationNodes } + { loop ? 'end_loop' : null }
); } }); -module.exports = Loop; \ No newline at end of file +module.exports = Loop; diff --git a/components/content/loop/navigation/post-navigation.jsx b/components/content/loop/navigation/post-navigation.jsx index 93a84f3..822c4ba 100644 --- a/components/content/loop/navigation/post-navigation.jsx +++ b/components/content/loop/navigation/post-navigation.jsx @@ -6,7 +6,7 @@ var React = require( 'react/addons' ); /** * Renders links to the next and previous posts. */ -PostNavigation = React.createClass({ +var PostNavigation = React.createClass({ render: function() { var previousPostLink; @@ -38,4 +38,4 @@ PostNavigation = React.createClass({ } }); -module.exports = PostNavigation; \ No newline at end of file +module.exports = PostNavigation; diff --git a/components/router/router.jsx b/components/router/router.jsx index 306fa93..cded214 100644 --- a/components/router/router.jsx +++ b/components/router/router.jsx @@ -19,7 +19,7 @@ var Router = React.createClass({ page( '/', function ( ctx ) { var data, slug = ctx.params.slug, - url = "/wp-json/posts"; + url = "/wp-json/wp/v2/posts"; request .get( url ) .end( function( err, res ) { @@ -31,7 +31,7 @@ var Router = React.createClass({ page( '/:year/:month/:day/:slug', function ( ctx ) { var data, slug = ctx.params.slug, - url = "/wp-json/posts/?filter[name]=" + slug; + url = "/wp-json/wp/v2/posts/?filter[name]=" + slug; request .get( url ) .end( function( err, res ) { @@ -56,7 +56,7 @@ var Router = React.createClass({ slug = slug.substr(0, slug.length - 1); } var part = slug.substring(slug.lastIndexOf('/') + 1); - var url = "/wp-json/posts/?type[]=page&filter[name]=" + part; + var url = "/wp-json/wp/v2/pages/?filter[name]=" + part; request .get( url ) .end( function( err, res ) { @@ -82,4 +82,4 @@ var Router = React.createClass({ }); -module.exports = Router; \ No newline at end of file +module.exports = Router; diff --git a/footer.php b/footer.php new file mode 100644 index 0000000..94ae05e --- /dev/null +++ b/footer.php @@ -0,0 +1,17 @@ + +
+
+ +
+
+ + | + Automattic' ); ?> +
+
+
+ + + + + diff --git a/functions.php b/functions.php index 53a8d2a..9afdd18 100644 --- a/functions.php +++ b/functions.php @@ -151,41 +151,3 @@ function picard_get_json( $_post ) { } add_filter( 'json_prepare_post', 'picard_get_json' ); - -function picard_api_init() { - global $picard_api_comments; - - $picard_api_comments = new Picard_API_Comments(); - add_filter( 'json_endpoints', array( $picard_api_comments, 'register_routes' ) ); -} -add_action( 'wp_json_server_before_serve', 'picard_api_init' ); - -class Picard_API_Comments extends WP_JSON_Comments { - public function register_routes( $routes ) { - $routes['/picard/comments'] = array( - array( array( $this, 'new_post' ), WP_JSON_Server::CREATABLE ), - ); - - return $routes; - } - - public function new_post() { - - $commentdata = array( - 'comment_post_ID' => $_POST['comment_post_ID'], - 'comment_author' => $_POST['comment_author'], - 'comment_author_email' => $_POST['comment_author_email'], - 'comment_author_url' => $_POST['comment_author_url'], - 'comment_content' => $_POST['content'], - 'comment_author_IP' => $_SERVER['REMOTE_ADDR'], - 'comment_type' => '', - ); - $comment_id = wp_new_comment( $commentdata ); - - $new_comment = get_comment( $comment_id ); - - $prepared_comment = $this->prepare_comment( $new_comment ); - - return ( $comment_id ) ? $prepared_comment : array(); - } -} diff --git a/header.php b/header.php new file mode 100644 index 0000000..6548957 --- /dev/null +++ b/header.php @@ -0,0 +1,30 @@ + +> + + + + + + + + +> +
+ + + + +
+
+
diff --git a/index.php b/index.php index 1afc74a..d8d756a 100644 --- a/index.php +++ b/index.php @@ -1,65 +1 @@ - -> - - - - - - - - -> -
- - - - -
-
-
- - - - - - - - - - - - - - - - - - -
-
-
- -
-
- - | - Automattic' ); ?> -
-
-
- - - - - \ No newline at end of file +

\ No newline at end of file diff --git a/package.json b/package.json index d506e3e..65adb1c 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,8 @@ }, "homepage": "https://github.com/Automattic/Picard", "devDependencies": { + "babel": "^5.8.23", + "babel-runtime": "^5.8.25", "browserify": "~7.0.3", "gulp": "~3.8.10", "gulp-autoprefixer": "^2.0.0", diff --git a/page.php b/page.php new file mode 100644 index 0000000..c427a95 --- /dev/null +++ b/page.php @@ -0,0 +1 @@ +

Comments

    Leave a reply

    Your email address will not be published. Required fields are marked *

    \ No newline at end of file diff --git a/sample.json b/sample.json new file mode 100644 index 0000000..2c56ba1 --- /dev/null +++ b/sample.json @@ -0,0 +1,12 @@ +[{ + "id": "the_id", + "date": "the_date", + "link": "the_link", + "title": { + "rendered": "the_title" + }, + "content": { + "rendered": "the_content" + }, + "loop": "the_loop" +}] diff --git a/single.php b/single.php new file mode 100644 index 0000000..ca0f2cc --- /dev/null +++ b/single.php @@ -0,0 +1 @@ +

    Comments

      Leave a reply

      Your email address will not be published. Required fields are marked *

      \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..8e0ccaa --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,57 @@ +var fs = require( 'fs' ), + data = require( './sample.json' ), + React = require( 'react' ), + babel = require( 'babel/register' ), + //posts = require( './components/content/content.jsx' ); + posts = React.createFactory( require( './components/content/content.jsx' ) ); + +//data = JSON.parse( data ); + +var markup = ""; +markup += React.renderToStaticMarkup( posts({ data: data, bodyClass: 'index' }) ); +markup += ""; + +markup = markup.replace( /the_title/gi, '' ); +markup = markup.replace( /the_link/gi, '' ); +markup = markup.replace( /the_date/gi, '' ); +markup = markup.replace( /the_content/gi, '' ); +markup = markup.replace( /the_loop/gi, ''); +markup = markup.replace( /end_loop/gi, '' ); + +console.log( markup ); + +fs.writeFileSync( 'index.php', markup ); + + + +markup = ""; +markup += React.renderToStaticMarkup( posts({ data: data, bodyClass: 'page' }) ); +markup += ""; + +markup = markup.replace( /the_title/gi, '' ); +markup = markup.replace( /the_link/gi, '' ); +markup = markup.replace( /the_date/gi, '' ); +markup = markup.replace( /the_content/gi, '' ); +markup = markup.replace( /the_loop/gi, ''); +markup = markup.replace( /end_loop/gi, '' ); + +console.log( markup ); + +fs.writeFileSync( 'page.php', markup ); + + + +markup = ""; +markup += React.renderToStaticMarkup( posts({ data: data, bodyClass: 'single' }) ); +markup += ""; + +markup = markup.replace( /the_title/gi, '' ); +markup = markup.replace( /the_link/gi, '' ); +markup = markup.replace( /the_date/gi, '' ); +markup = markup.replace( /the_content/gi, '' ); +markup = markup.replace( /the_loop/gi, ''); +markup = markup.replace( /end_loop/gi, '' ); + +console.log( markup ); + +fs.writeFileSync( 'single.php', markup );