Skip to content

Commit

Permalink
Submitting Multiple Site Showcase Contributions (#21501)
Browse files Browse the repository at this point in the history
* updated sites.yml to add contribution sites

* updated sites.yml formatting

* fixing TypeError bug for submission
  • Loading branch information
axthomas29 authored Feb 16, 2020
1 parent 419fa30 commit 9357549
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/sites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9722,3 +9722,26 @@
built_by: Hazem Osama
built_by_url: https://github.com/hazem3500
featured: false
- title: Alexandra Thomas
main_url: "https://alexandracthomas.com/"
url: "https://alexandracthomas.com/"
description: >
A portfolio site for Alexandra Thomas, a front-end developer with creative super powers based in Charlotte, NC.
categories:
- Portfolio
- Blog
- Web Development
featured: false
- title: Storto Productions
main_url: "https://www.storto-productions.com/"
url: "https://www.storto-productions.com/about/"
featured: false
description: >
A portfolio site for a video production company based out of Phoenix, AZ.
categories:
- Video
- Blog
- Portfolio
- Business
built_by: Alexandra Thomas
built_by_url: "https://alexandracthomas.com/"
50 changes: 50 additions & 0 deletions packages/gatsby-transformer-remark/utils/time-to-read.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use strict";

exports.__esModule = true;
exports.timeToRead = void 0;

const sanitizeHTML = require(`sanitize-html`);

const _ = require(`lodash`); // Unicode ranges for Han (Chinese) and Hiragana/Katakana (Japanese) characters


const cjRanges = [[11904, 11930], // Han
[11931, 12020], [12032, 12246], [12293, 12294], [12295, 12296], [12321, 12330], [12344, 12348], [13312, 19894], [19968, 40939], [63744, 64110], [64112, 64218], [131072, 173783], [173824, 177973], [177984, 178206], [178208, 183970], [183984, 191457], [194560, 195102], [12353, 12439], // Hiragana
[12445, 12448], [110593, 110879], [127488, 127489], [12449, 12539], // Katakana
[12541, 12544], [12784, 12800], [13008, 13055], [13056, 13144], [65382, 65392], [65393, 65438], [110592, 110593]];

function isCjChar(char) {
const charCode = char.codePointAt(0);
return cjRanges.some(([from, to]) => charCode >= from && charCode < to);
}

const timeToRead = html => {
let timeToRead = 0;
const pureText = sanitizeHTML(html, {
allowTags: []
});
const avgWPM = 265;
let latinChars = [];
let cjChars = [];

for (const char of pureText) {
if (isCjChar(char)) {
cjChars.push(char);
} else {
latinChars.push(char);
}
} // Multiply non-latin character string length by 0.56, because
// on average one word consists of 2 characters in both Chinese and Japanese


const wordCount = _.words(latinChars.join(``)).length + cjChars.length * 0.56;
timeToRead = Math.round(wordCount / avgWPM);

if (timeToRead === 0) {
timeToRead = 1;
}

return timeToRead;
};

exports.timeToRead = timeToRead;

0 comments on commit 9357549

Please sign in to comment.