bash: Fri Dec 6 02:46:54 CST 2019

dev
mashiro 4 years ago
parent ff9a63f593
commit 5fbfc541c7
  1. 14
      package-lock.json
  2. 4
      package.json
  3. 29
      src/php/comments.php
  4. 0
      src/scss/layouts/comment.scss
  5. 1
      src/scss/layouts/footer.scss
  6. 237
      src/ts/functions/commentbox.ts
  7. 11
      src/ts/functions/postPageInit.ts
  8. 53
      src/ts/utils/graphql.ts
  9. 139
      webpack.common.js
  10. 169
      webpack.config.js
  11. 0
      webpack.dev.js
  12. 0
      webpack.prod.js
  13. 26
      webpack/webpack.i18n.js

14
package-lock.json generated

@ -5402,6 +5402,11 @@
"resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-1.0.0.tgz",
"integrity": "sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM="
},
"i18n-webpack-plugin": {
"version": "1.0.0",
"resolved": "http://mirrors.cloud.tencent.com/npm/i18n-webpack-plugin/-/i18n-webpack-plugin-1.0.0.tgz",
"integrity": "sha512-WMC2i05OuitjxYmeQU8XV4KJ+CrWnTOY5DwjygRz2dNByezfnTbVbV67qX4I53KHlscSnOsJyv6StuZxmm6J7w=="
},
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
@ -9784,6 +9789,15 @@
"uuid": "^3.3.2"
}
},
"webpack-merge": {
"version": "4.2.2",
"resolved": "http://mirrors.cloud.tencent.com/npm/webpack-merge/-/webpack-merge-4.2.2.tgz",
"integrity": "sha512-TUE1UGoTX2Cd42j3krGYqObZbOD+xF7u28WB7tfUordytSjbWTIjK/8V0amkBfTYN4/pB/GIDlJZZ657BGG19g==",
"dev": true,
"requires": {
"lodash": "^4.17.15"
}
},
"webpack-sources": {
"version": "1.4.3",
"resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.4.3.tgz",

@ -25,6 +25,7 @@
"graphql": "^14.5.8",
"graphql-tag": "^2.10.1",
"html-loader": "^0.5.5",
"i18n-webpack-plugin": "^1.0.0",
"material-components-web": "^3.2.0",
"node-sass": "^4.13.0",
"parallax-js": "^3.1.0",
@ -50,7 +51,8 @@
"terser-webpack-plugin": "^2.2.1",
"ts-loader": "^6.2.1",
"typescript": "^3.6.4",
"uglifyjs-webpack-plugin": "^2.2.0"
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack-merge": "^4.2.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",

@ -1,24 +1,29 @@
<div id="comments" class="comments">
<?php if ( post_password_required() ) : ?>
<p><?php esc_html_e( 'Post is password protected. Enter the password to view any comments.', 'html5blank' ); ?></p>
<?php if (post_password_required()): ?>
<p><?php esc_html_e('Post is password protected. Enter the password to view any comments.', 'html5blank');?></p>
</div>
<?php return; endif; ?>
<?php return;endif;?>
<?php if ( have_comments() ) : ?>
<?php if (have_comments()): ?>
<h2><?php comments_number(); ?></h2>
<h2><?php comments_number();?></h2>
<ul>
<?php wp_list_comments( 'type=comment&callback=html5blankcomments' ); // Custom callback in functions.php. ?>
</ul>
<!-- TODO: also generate a copy in php side for SEO -->
<ul id="comment-list-ul" class="comment-list"></ul>
<?php elseif ( ! comments_open() && ! is_page() && post_type_supports( get_post_type(), 'comments' ) ) : ?>
<template id="comment-list-li-template">
<li>
<img class="avatar">
<div class="name"></div>
<div class="content"><div>
</li>
</template>
<p><?php esc_html_e( 'Comments are closed here.', 'html5blank' ); ?></p>
<?php elseif (!comments_open() && !is_page() && post_type_supports(get_post_type(), 'comments')): ?>
<?php endif; ?>
<p><?php esc_html_e('Comments are closed here.', 'sakura');?></p>
<?php comment_form(); ?>
<?php endif;?>
</div>

@ -7,6 +7,7 @@
footer {
position: relative;
margin-top: 60px;
background-color: $mdc-theme-primary;
.before {

@ -0,0 +1,237 @@
import { getPostCommentByPostId } from '../utils/graphql'
import ApolloClient from 'apollo-boost'
const getCommentData = function (callback: Function) {
const theCommentQuery: getPostCommentByPostId = new getPostCommentByPostId(1, 5)
const client: ApolloClient = new ApolloClient()
client.query(theCommentQuery.query)
.then(data => callback(data))
.catch(error => console.log(error))
}
const pushNewCommentItem = function (data: object) {
let li = document.querySelector('#comment-list-li-template'),
ul = document.querySelector('#comment-list-ul')
li.content.querySelector('.name').textContent = data.name
li.content.querySelector('.content').innerHTML = data.content.trim()
let clone = document.importNode(li.content, true)
ul.appendChild(clone)
}
const getCommentDataCallback = function (data: object) {
//single item data
interface CommentItem {
name: string,
content: string
}
for (let edge: object in data.data.postBy.comments.edges) {
let node: object = data.data.postBy.comments.edges[edge].node
let stata: CommentItem = {
name: node.author.name,
content: node.content
}
pushNewCommentItem(stata)
}
}
const main = async function () {
getCommentData(getCommentDataCallback)
// dev(getCommentDataCallback)
}
export default main
const dev = function (callback: Function) {
const data: object = {
"data": {
"postBy": {
"id": "cG9zdDox",
"postId": 1,
"comments": {
"edges": [{
"node": {
"date": "2019-12-05 15:15:21",
"agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/78.0.3904.108 Safari\/537.36",
"content": "<p>dsgssdg<\/p>\n",
"commentId": 20,
"author": {
"email": "adadam@qq.com",
"name": "mashiro",
"url": null,
"__typename": "User"
},
"authorIp": "101.87.249.108",
"__typename": "Comment",
"children": {
"nodes": [{
"date": "2019-12-05 15:30:27",
"agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/78.0.3904.108 Safari\/537.36",
"content": "<p>re:fsadgfbad<\/p>\n",
"commentId": 24,
"author": {
"email": "adadam@qq.com",
"name": "mashiro",
"url": null,
"__typename": "User"
},
"authorIp": "101.87.249.108",
"__typename": "Comment",
"children": {
"nodes": [],
"__typename": "CommentToCommentConnection"
}
}, {
"date": "2019-12-05 15:30:19",
"agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/78.0.3904.108 Safari\/537.36",
"content": "<p>re:24325<\/p>\n",
"commentId": 23,
"author": {
"email": "adadam@qq.com",
"name": "mashiro",
"url": null,
"__typename": "User"
},
"authorIp": "101.87.249.108",
"__typename": "Comment",
"children": {
"nodes": [],
"__typename": "CommentToCommentConnection"
}
}, {
"date": "2019-12-05 15:29:56",
"agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/78.0.3904.108 Safari\/537.36",
"content": "<p>reply233<\/p>\n",
"commentId": 21,
"author": {
"email": "adadam@qq.com",
"name": "mashiro",
"url": null,
"__typename": "User"
},
"authorIp": "101.87.249.108",
"__typename": "Comment",
"children": {
"nodes": [{
"date": "2019-12-05 15:30:09",
"agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/78.0.3904.108 Safari\/537.36",
"content": "<p>re:re:2333<\/p>\n",
"commentId": 22,
"author": {
"email": "adadam@qq.com",
"name": "mashiro",
"url": null,
"__typename": "User"
},
"authorIp": "101.87.249.108",
"__typename": "Comment",
"children": {
"nodes": [],
"__typename": "CommentToCommentConnection"
}
}],
"__typename": "CommentToCommentConnection"
}
}],
"__typename": "CommentToCommentConnection"
}
},
"__typename": "PostToCommentConnectionEdge"
}, {
"node": {
"date": "2019-12-05 15:15:18",
"agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/78.0.3904.108 Safari\/537.36",
"content": "<p>asfadsfgasg<\/p>\n",
"commentId": 19,
"author": {
"email": "adadam@qq.com",
"name": "mashiro",
"url": null,
"__typename": "User"
},
"authorIp": "101.87.249.108",
"__typename": "Comment",
"children": {
"nodes": [],
"__typename": "CommentToCommentConnection"
}
},
"__typename": "PostToCommentConnectionEdge"
}, {
"node": {
"date": "2019-12-05 15:15:15",
"agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/78.0.3904.108 Safari\/537.36",
"content": "<p>asfasfas<\/p>\n",
"commentId": 18,
"author": {
"email": "adadam@qq.com",
"name": "mashiro",
"url": null,
"__typename": "User"
},
"authorIp": "101.87.249.108",
"__typename": "Comment",
"children": {
"nodes": [],
"__typename": "CommentToCommentConnection"
}
},
"__typename": "PostToCommentConnectionEdge"
}, {
"node": {
"date": "2019-12-05 15:15:12",
"agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/78.0.3904.108 Safari\/537.36",
"content": "<p>safassfs<\/p>\n",
"commentId": 17,
"author": {
"email": "adadam@qq.com",
"name": "mashiro",
"url": null,
"__typename": "User"
},
"authorIp": "101.87.249.108",
"__typename": "Comment",
"children": {
"nodes": [],
"__typename": "CommentToCommentConnection"
}
},
"__typename": "PostToCommentConnectionEdge"
}, {
"node": {
"date": "2019-12-05 15:15:08",
"agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/78.0.3904.108 Safari\/537.36",
"content": "<p>adfasf<\/p>\n",
"commentId": 16,
"author": {
"email": "adadam@qq.com",
"name": "mashiro",
"url": null,
"__typename": "User"
},
"authorIp": "101.87.249.108",
"__typename": "Comment",
"children": {
"nodes": [],
"__typename": "CommentToCommentConnection"
}
},
"__typename": "PostToCommentConnectionEdge"
}],
"pageInfo": {
"endCursor": "YXJyYXljb25uZWN0aW9uOjE2",
"hasNextPage": true,
"hasPreviousPage": false,
"startCursor": "YXJyYXljb25uZWN0aW9uOjIw",
"__typename": "WPPageInfo"
},
"__typename": "PostToCommentConnection"
},
"__typename": "Post"
}
}
}
callback(data)
}

@ -1,13 +1,8 @@
import { getPostCommentByPostId } from '../utils/graphql'
import commentBoxInit from './commentbox'
/**
* Site top bar handler when page scroll
*/
export default function () {
export default async function () {
if (!document.querySelector('article').classList.contains('markdown')) {
return
}
let theComment = new getPostCommentByPostId(1, 5)
console.log(theComment.query())
console.log('test')
commentBoxInit()
}

@ -4,6 +4,7 @@ import gql from 'graphql-tag'
class getPostCommentByPostId {
private postId: number
private MaxChildrenLevel: number
public query: object
/**
* Get post comment bay wp post id through GraphQL
@ -16,6 +17,7 @@ class getPostCommentByPostId {
public constructor(postId: number, MaxChildrenLevel) {
this.postId = postId
this.MaxChildrenLevel = MaxChildrenLevel
this.gqlstring()
}
private queryChildren() {
@ -38,30 +40,28 @@ children {
queryHeader = addTabs(childrenHeader + queryHeader, 2)
queryFooter = addTabs(queryFooter + childrenFooter, 2)
}
return addTabs(queryHeader + queryFooter, 2)
return addTabs(queryHeader + queryFooter, 3)
}
/**
* @return {any} GraphQL query json string
*/
public query() {
let result: object
const client: ApolloClient = new ApolloClient()
client.query({
// TODO: GraphQL Schema to Typescript interface?
private gqlstring(): void {
this.query = {
query: gql`
query GET_POST($postId: Int) {
query GET_POST($postId: Int, $first: Int, $after: String) {
postBy(postId: $postId) {
id
postId
title
date
uri
content
}
comments {
edges {
node {
...CommentFields${this.queryChildren()}
comments(first: $first, after: $after) {
edges {
node {
...CommentFields${this.queryChildren()}
}
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
}
@ -73,7 +73,7 @@ fragment CommentFields on Comment {
content(format: RENDERED)
commentId
author {
... on CommentAuthor {
... on User {
email
name
url
@ -81,18 +81,13 @@ fragment CommentFields on Comment {
}
authorIp
}
`,
`,
variables: {
"postId": this.postId
"postId": 1,
"first": 5,
"after": null
},
})
.then(data => {
result = data
}) // 异步好烦
// .then(data => console.log(data))
.catch(error => console.log(error))
return result
}
}
}

@ -0,0 +1,139 @@
const path = require('path');
const autoprefixer = require('autoprefixer');
const TerserPlugin = require('terser-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const RemovePlugin = require('remove-files-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const Chunks2JsonPlugin = require('chunks-2-json-webpack-plugin');
// const OutputPath = process.env.ENV_MODE
module.exports = [{
mode: "development", // "production" | "development" | "none"
entry: {
main: ['./src/ts/index.ts', './src/scss/index.scss']
},
output: {
path: path.resolve(__dirname, './dist'),
filename: './js/bundle_[hash].js'
},
devtool: 'inline-source-map',
devServer: {
contentBase: path.join(__dirname, './dist'),
publicPath: '/',
port: 8080,
host: '0.0.0.0',
compress: true,
},
watchOptions: {
aggregateTimeout: 300,
ignored: /node_modules/
},
module: {
rules: [{
test: /\.(png|jpg|gif|svg)$/,
exclude: [
path.resolve(__dirname, './node_modules'),
],
use: {
loader: 'file-loader',
options: {
name: '../images/[hash].[ext]'
},
},
},
{
test: /\.scss$/,
use: [{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
plugins: () => [autoprefixer()]
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
sassOptions: {
includePaths: ['./node_modules']
},
}
},
]
},
{
test: /\.tsx?$/,
use: [{
loader: 'babel-loader',
query: {
presets: ['@babel/preset-typescript'],
},
}],
exclude: /node_modules/
},
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader'
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
// optimization: {
// minimize: true,
// minimizer: [new TerserPlugin({
// sourceMap: false,
// })],
// },
plugins: [
new CopyPlugin([{
from: './src/package.scss',
to: './style.css',
toType: 'file',
},
{
from: './src/screenshot.png',
to: './screenshot.png',
toType: 'file',
},
{
from: './src/images/',
to: './images/[hash].[ext]',
toType: 'template',
},
{
from: './src/php/*.php',
to: './[name].[ext]',
toType: 'template',
},
{
from: './src/php/*/*.php',
to: './[1]/[2].[ext]',
test: /src\/php\/([^/]+)\/(.+)\.php$/,
}
]),
new RemovePlugin({
before: {
include: ['./dist']
},
after: {
include: ['./images']
}
}),
new MiniCssExtractPlugin({
filename: "./css/bundle_[hash].css",
}),
new Chunks2JsonPlugin({
outputDir: 'dist/',
filename: 'manifest.json'
})
],
}];

@ -1,154 +1,17 @@
const path = require('path');
const autoprefixer = require('autoprefixer');
const TerserPlugin = require('terser-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const RemovePlugin = require('remove-files-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const Chunks2JsonPlugin = require('chunks-2-json-webpack-plugin');
const merge = require("webpack-merge")
const commonConfig = require("./webpack.common")
const devConfig = require("./webpack.dev")
const prodConfig = require("./webpack.prod")
const i18nConfig = require("./webpack/webpack.i18n")
// const OutputPath = process.env.ENV_MODE
module.exports = [{
mode: "development", // "production" | "development" | "none"
entry: {
main: ['./src/ts/index.ts', './src/scss/index.scss']
},
output: {
path: path.resolve(__dirname, './dist'),
filename: './js/bundle_[hash].js'
},
devtool: 'inline-source-map',
devServer: {
contentBase: path.join(__dirname, './dist'),
publicPath: '/',
port: 8080,
host: '0.0.0.0',
// proxy: {},
compress: true,
// historyApiFallback: true,
},
watchOptions: {
aggregateTimeout: 300,
//poll: 1000, // specifying a poll interval in milliseconds
ignored: /node_modules/
},
module: {
rules: [{
test: /\.(png|jpg|gif|svg)$/,
exclude: [
path.resolve(__dirname, './node_modules'),
],
use: {
loader: 'file-loader',
options: {
// name(file) {
// return './images/[name].[ext]';
// },
name: '../images/[hash].[ext]'
// outputPath: './images',
},
},
},
{
test: /\.scss$/,
use: [{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
plugins: () => [autoprefixer()]
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
sassOptions: {
includePaths: ['./node_modules']
},
}
},
]
},
{
test: /\.tsx?$/,
use: [{
loader: 'babel-loader',
query: {
presets: ['@babel/preset-typescript'],
},
}, ],
exclude: /node_modules/
},
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader'
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
// optimization: {
// minimize: true,
// minimizer: [new TerserPlugin({
// sourceMap: false,
// })],
// },
plugins: [
new CopyPlugin([{
from: './src/package.scss',
to: './style.css',
toType: 'file',
},
{
from: './src/screenshot.png',
to: './screenshot.png',
toType: 'file',
},
{
from: './src/images/',
to: './images/[hash].[ext]',
toType: 'template',
},
// {
// from: './src/*.html',
// to: './[name].[ext]',
// toType: 'template',
// },
{
from: './src/php/*.php',
to: './[name].[ext]',
toType: 'template',
},
{
from: './src/php/*/*.php',
to: './[1]/[2].[ext]',
test: /src\/php\/([^/]+)\/(.+)\.php$/,
}
]),
new RemovePlugin({
before: {
include: ['./dist']
},
after: {
include: ['./images']
}
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: "./css/bundle_[hash].css",
// chunkFilename: "[id].css"
}),
new Chunks2JsonPlugin({
outputDir: 'dist/',
filename: 'manifest.json'
})
],
}];
module.exports = mode => {
// if (mode === "production") {
// return merge(commConfig, prodConfig, {
// mode
// })
// }
// return merge(commonConfig, {
// mode: "development", // "production" | "development" | "none"
// })
return commonConfig
}

@ -0,0 +1,26 @@
const path = require("path");
const glob = require("glob");
const I18nPlugin = require("i18n-webpack-plugin");
const PATHS = {
build: path.join(__dirname, "i18n-build"),
i18nDemo: path.join(__dirname, "app", "i18n.js"),
};
const TRANSLATIONS = [{ language: "en" }].concat(
glob.sync("./languages/*.json").map(file => ({
language: path.basename(file, path.extname(file)),
translation: require(file),
}))
);
module.exports = TRANSLATIONS.map(({ language, translation }) => ({
entry: {
index: PATHS.i18nDemo,
},
output: {
path: PATHS.build,
filename: `[name].${language}.js`,
},
plugins: [new I18nPlugin(translation)],
}));
Loading…
Cancel
Save