-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Added Reading Time and Word Count to the Insights
- Loading branch information
Showing
17 changed files
with
178 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import {connect} from 'react-redux'; | ||
import LoadingIndicator from './LoadingIndicator'; | ||
import { __, _n } from "@wordpress/i18n"; | ||
import { InsightsCard } from "@yoast/components"; | ||
|
||
const ReadingTime = ({readingTime}) => { | ||
if (readingTime) { | ||
const estimatedReadingTime = readingTime.result; | ||
return <InsightsCard | ||
amount={ estimatedReadingTime } | ||
unit={ _n( "minute", "minutes", estimatedReadingTime, "wordpress-seo" ) } | ||
title={ __( "Reading time", "wordpress-seo" ) } | ||
linkTo={ 'https://yoa.st/4fd' } | ||
linkText={ __( "Learn more about reading time", "wordpress-seo" ) } | ||
/> | ||
} | ||
return <LoadingIndicator /> | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
...state.readingTime | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps)(ReadingTime); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import {connect} from 'react-redux'; | ||
import LoadingIndicator from './LoadingIndicator'; | ||
import { __, _n } from "@wordpress/i18n"; | ||
import { InsightsCard } from "@yoast/components"; | ||
|
||
const WordCount = ({wordCount}) => { | ||
if (wordCount) { | ||
let unitString = _n( "word", "words", wordCount.result.count, "wordpress-seo" ); | ||
let titleString = __( "Word count", "wordpress-seo" ); | ||
let linkText = __( "Learn more about word count", "wordpress-seo" ); | ||
if ( wordCount.result.unit === "character" ) { | ||
unitString = _n( "character", "characters", wordCount.result.count, "wordpress-seo" ); | ||
titleString = __( "Character count", "wordpress-seo" ); | ||
linkText = __( "Learn more about character count", "wordpress-seo" ); | ||
} | ||
|
||
return <InsightsCard | ||
amount={ wordCount.result.count } | ||
unit={ unitString } | ||
title={ titleString } | ||
//linkTo={ 'https://yoa.st/word-count' } | ||
linkText={ linkText } | ||
/> | ||
} | ||
return <LoadingIndicator /> | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
...state.wordCount | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps)(WordCount); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const GET_READINGTIME_REQUEST = 'GET_READINGTIME_REQUEST'; | ||
export const GET_READINGTIME_SUCCESS = 'GET_READINGTIME_SUCCESS'; | ||
|
||
export function getReadingTime(worker, paper) { | ||
return dispatch => { | ||
dispatch({type: GET_READINGTIME_REQUEST}); | ||
|
||
return worker | ||
.runResearch('readingTime', paper) | ||
.then((results) => { | ||
dispatch({type: GET_READINGTIME_SUCCESS, payload: results}); | ||
}).catch((error) => { | ||
console.error('An error occured while analyzing the text:'); | ||
console.error(error); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const GET_WORDCOUNT_REQUEST = 'GET_WORDCOUNT_REQUEST'; | ||
export const GET_WORDCOUNT_SUCCESS = 'GET_WORDCOUNT_SUCCESS'; | ||
|
||
export function getWordCount(worker, paper) { | ||
return dispatch => { | ||
dispatch({type: GET_WORDCOUNT_REQUEST}); | ||
|
||
return worker | ||
.runResearch('wordCountInText', paper) | ||
.then((results) => { | ||
dispatch({type: GET_WORDCOUNT_SUCCESS, payload: results}); | ||
}).catch((error) => { | ||
console.error('An error occured while analyzing the text:'); | ||
console.error(error); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {GET_READINGTIME_REQUEST, GET_READINGTIME_SUCCESS} from '../actions/readingTime'; | ||
|
||
const initialState = { | ||
isCheckingReadingTime: false | ||
}; | ||
|
||
function readingTimeReducer (state = initialState, action) { | ||
switch(action.type) { | ||
case GET_READINGTIME_REQUEST: | ||
return {...state, isCheckingReadingTime: true}; | ||
case GET_READINGTIME_SUCCESS: | ||
return {...state, isCheckingReadingTime: false, readingTime: action.payload}; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default readingTimeReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {GET_WORDCOUNT_REQUEST, GET_WORDCOUNT_SUCCESS} from '../actions/wordCount'; | ||
|
||
const initialState = { | ||
isCheckingWordCount: false | ||
}; | ||
|
||
function wordCountReducer (state = initialState, action) { | ||
switch(action.type) { | ||
case GET_WORDCOUNT_REQUEST: | ||
return {...state, isCheckingWordCount: true}; | ||
case GET_WORDCOUNT_SUCCESS: | ||
return {...state, isCheckingWordCount: false, wordCount: action.payload}; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default wordCountReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
<html data-namespace-typo3-fluid="true" xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"> | ||
<div class="yoastSeo-insights"> | ||
<div data-yoast-insights></div> | ||
<div data-yoast-flesch></div> | ||
<div data-yoast-readingtime></div> | ||
<div data-yoast-wordcount></div> | ||
<div class="yoast-insights-row"> | ||
<div data-yoast-flesch></div> | ||
</div> | ||
<div class="yoast-insights-row"> | ||
<div data-yoast-readingtime></div> | ||
<div data-yoast-wordcount></div> | ||
</div> | ||
</div> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.