-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from florianeckerstorfer/gatsby-plugin
Add Gatsby plugin
- Loading branch information
Showing
13 changed files
with
259 additions
and
57 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,26 @@ | ||
name: Integration tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test_integration: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [12.x, 14.x, 15.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Build project | ||
run: npm run build | ||
- name: Run integration tests | ||
run: npm run test:integration | ||
env: | ||
CI: true |
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,24 +1,24 @@ | ||
name: Test | ||
name: Unit tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
test_unit: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [10.x, 12.x, 14.x] | ||
node-version: [10.x, 12.x, 14.x, 15.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Run tests | ||
run: npm test -- --coverage | ||
env: | ||
CI: true | ||
- uses: actions/checkout@v1 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Run tests | ||
run: npm test -- --coverage | ||
env: | ||
CI: true |
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,47 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
echo ">>> Clean up previous integration test run..." | ||
sh -c "rm -rf gatsby-integration-test" | ||
sh -c "rm -rf ./scripts/storage" | ||
|
||
local_registry="http://localhost:4873" | ||
|
||
echo ">>> Starting Gatsby installation..." | ||
mkdir -p ~/.config/gatsby | ||
echo '{ "telemetry": { "enabled": false }, "cli": { "packageManager": "npm" } }' > ~/.config/gatsby/config.json | ||
npx gatsby new gatsby-integration-test https://github.com/gatsbyjs/gatsby-starter-blog | ||
|
||
echo ">>> Start local registry..." | ||
tmp_registry_log=`mktemp` | ||
echo "Local registry output file=$tmp_registry_log" | ||
nohup npx verdaccio --config ./scripts/verdaccio.yaml &>$tmp_registry_log & | ||
grep -q 'http address' <(tail -f $tmp_registry_log) | ||
|
||
echo ">>> Login to local registry and publish package..." | ||
npx npm-auth-to-token -u test -p test -e test@test.com --registry $local_registry | ||
npm --registry $local_registry publish | ||
|
||
echo ">>> Install '@fec/remark-a11y-emoji' from local registry..." | ||
cd gatsby-integration-test | ||
npm install @fec/remark-a11y-emoji --registry $local_registry | ||
|
||
echo ">>> Configure plugin and add emoji to a page..." | ||
sed -i -e 's/gatsby-remark-smartypants/@fec\/remark-a11y-emoji\/gatsby/g' gatsby-config.js | ||
echo '🎸🎤👯♂️' >> content/blog/hello-world/index.md | ||
|
||
echo ">>> Build Gatsby..." | ||
npx gatsby build | ||
|
||
echo ">>> Check if Emoji was been converted..." | ||
# grep guitar public/hello-world/index.html | ||
echo "another check" | ||
if grep -q guitar public/hello-world/index.html | ||
then | ||
echo "Success, emoji is wrapped with A11y information" | ||
exit 0 | ||
else | ||
echo "Failure, emoji is not wrapped with A11y information" | ||
exit 1 | ||
fi |
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,45 @@ | ||
import plugin from '../src/gatsby'; | ||
import Remark from 'remark'; | ||
import visit from 'unist-util-visit'; | ||
|
||
describe('remark-a11y-emoji/gatsby', () => { | ||
let remark; | ||
|
||
beforeEach(() => { | ||
remark = new Remark().data('settings', { | ||
commonmark: true, | ||
footnotes: true, | ||
pedantic: true, | ||
}); | ||
}); | ||
|
||
it('should return HTML for "🎸"', () => { | ||
const markdownAST = remark.parse('🎸'); | ||
const result = plugin({ markdownAST }); | ||
|
||
visit(result, 'html', (node) => { | ||
expect(node.value).toBe('<span role="img" aria-label="guitar">🎸</span>'); | ||
}); | ||
}); | ||
|
||
it('should return HTML for "foo 🎸 bar 🎧 qoo"', () => { | ||
const markdownAST = remark.parse('foo 🎸 bar 🎧 qoo'); | ||
const result = plugin({ markdownAST }); | ||
|
||
visit(result, 'html', (node) => { | ||
expect(node.value).toBe( | ||
'foo <span role="img" aria-label="guitar">🎸</span> bar <span role="img" aria-label="headphone">🎧</span> qoo' | ||
); | ||
}); | ||
}); | ||
|
||
it('should return do nothing to other nodes', async () => { | ||
const markdownAST = remark.parse('foo **bar**'); | ||
|
||
const transformed = await plugin({ | ||
markdownAST: Object.assign({}, markdownAST), | ||
}); | ||
|
||
expect(transformed).toEqual(markdownAST); | ||
}); | ||
}); |
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,4 @@ | ||
{ | ||
"name": "@fec/gatsby-remark-a11y-emoji", | ||
"main": "index.js" | ||
} |
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,31 @@ | ||
storage: ./storage | ||
|
||
auth: | ||
htpasswd: | ||
file: ./htpasswd | ||
|
||
uplinks: | ||
npmjs: | ||
url: https://registry.npmjs.org/ | ||
cache: true | ||
|
||
packages: | ||
'@fec/remark-a11y-emoji': | ||
access: $all | ||
publish: $all | ||
|
||
'@*/*': | ||
access: $all | ||
publish: $all | ||
proxy: npmjs | ||
|
||
'**': | ||
access: $all | ||
publish: $all | ||
proxy: npmjs | ||
|
||
logs: | ||
- { type: stdout, format: pretty, level: http } | ||
|
||
server: | ||
keepAliveTimeout: 0 |
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 emojiRegex from 'emoji-regex'; | ||
import visit from 'unist-util-visit'; | ||
import { getEmojiDescription } from './helper'; | ||
|
||
function a11yEmoji({ markdownAST }) { | ||
function visitor(node) { | ||
node.value = node.value.replace(emojiRegex(), (match) => { | ||
node.type = 'html'; | ||
const description = getEmojiDescription(match); | ||
return `<span role="img" aria-label="${description}">${match}</span>`; | ||
}); | ||
} | ||
|
||
visit(markdownAST, 'text', visitor); | ||
return markdownAST; | ||
} | ||
|
||
export default a11yEmoji; |
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,26 @@ | ||
import gemoji from 'gemoji'; | ||
import { skintoneMap, stripSkintone } from './skintone'; | ||
|
||
function emojiToName(emoji) { | ||
return gemoji.find((item) => item.emoji === emoji); | ||
} | ||
|
||
export function getEmojiDescription(emoji) { | ||
const { skintone, genericEmoji } = stripSkintone(emoji); | ||
|
||
let info = emojiToName(genericEmoji); | ||
|
||
if (!info) { | ||
const appleEmoji = genericEmoji + '\uFE0F'; | ||
info = emojiToName(appleEmoji); | ||
|
||
if (!info) { | ||
return ''; | ||
} | ||
} | ||
|
||
const skintoneDescription = skintoneMap[skintone] || ''; | ||
return skintoneDescription | ||
? `${info.description} (${skintoneDescription})` | ||
: info.description; | ||
} |
Oops, something went wrong.