New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storybook #952
Merged
Storybook #952
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fb9a860
First attempt of using storybook for component dev
appinteractive 2b80c12
Added actions and accessibility addons
appinteractive cc64f43
added one more post story
appinteractive e8f1c04
Fixed small issues
appinteractive e4279c3
Fixed no-ssr in storybook
appinteractive 6d852b5
Added basic embed link rendering
appinteractive 30c5558
Add href to link
mattwr18 455eac1
Merge remote-tracking branch 'origin/master' into storybook
roschaefer 281026b
Downgrade css-loader to < 3.0.0
roschaefer f71e481
Fix import path
roschaefer 34f86c9
Merge remote-tracking branch 'origin/master' into storybook
roschaefer 72edf78
Meld a chaotic commit history into one commit
roschaefer c9e6d18
Followed @mattwr18's suggestions here:
roschaefer b6a5946
Merge remote-tracking branch 'origin/master' into storybook
roschaefer f1b28c8
Meld commits from master
roschaefer a6aa974
Merge remote-tracking branch 'origin/master' into storybook
roschaefer b797ce4
Follow @Tirokk's suggestions:
roschaefer 1aeb93f
Merge remote-tracking branch 'origin/master' into storybook
roschaefer 8093fec
Update URL regex taking e.g. "?" into account
roschaefer 52e0361
Fixing pasteRules for Embeds
roschaefer File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
15 changes: 4 additions & 11 deletions
15
backend/src/middleware/handleHtmlContent/notifications/extractMentionedUsers.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
import cheerio from 'cheerio' | ||
const ID_REGEX = /\/profile\/([\w\-.!~*'"(),]+)/g | ||
|
||
export default function(content) { | ||
if (!content) return [] | ||
const $ = cheerio.load(content) | ||
const urls = $('.mention') | ||
let userIds = $('a.mention[data-mention-id]') | ||
.map((_, el) => { | ||
return $(el).attr('href') | ||
return $(el).attr('data-mention-id') | ||
}) | ||
.get() | ||
const ids = [] | ||
urls.forEach(url => { | ||
let match | ||
while ((match = ID_REGEX.exec(url)) != null) { | ||
ids.push(match[1]) | ||
} | ||
}) | ||
return ids | ||
userIds = userIds.map(id => id.trim()).filter(id => !!id) | ||
return userIds | ||
} |
61 changes: 16 additions & 45 deletions
61
backend/src/middleware/handleHtmlContent/notifications/extractMentionedUsers.spec.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,30 @@ | ||
import extractMentionedUsers from './extractMentionedUsers' | ||
|
||
const contentWithMentions = | ||
'<p>Something inspirational about <a href="/profile/u2" class="not-a-mention" data-mention-id="bobs-id" target="_blank">@bob-der-baumeister</a> and <a href="/profile/u3/jenny-rostock" class="mention" data-mention-id="u3" target="_blank">@jenny-rostock</a>.</p>' | ||
const contentEmptyMentions = | ||
'<p>Something inspirational about <a href="/profile/u2" data-mention-id="" target="_blank">@bob-der-baumeister</a> and <a href="/profile/u3/jenny-rostock" class="mention" data-mention-id target="_blank">@jenny-rostock</a>.</p>' | ||
const contentWithPlainLinks = | ||
'<p>Something inspirational about <a class="mention" href="/profile/u2" target="_blank">@bob-der-baumeister</a> and <a href="/profile/u3" target="_blank">@jenny-rostock</a>.</p>' | ||
|
||
describe('extractMentionedUsers', () => { | ||
describe('content undefined', () => { | ||
it('returns empty array', () => { | ||
expect(extractMentionedUsers()).toEqual([]) | ||
}) | ||
}) | ||
|
||
describe('searches through links', () => { | ||
it('ignores links without .mention class', () => { | ||
const content = | ||
'<p>Something inspirational about <a href="/profile/u2" target="_blank">@bob-der-baumeister</a> and <a href="/profile/u3" target="_blank">@jenny-rostock</a>.</p>' | ||
expect(extractMentionedUsers(content)).toEqual([]) | ||
}) | ||
|
||
describe('given a link with .mention class', () => { | ||
it('extracts ids', () => { | ||
const content = | ||
'<p>Something inspirational about <a href="/profile/u2" class="mention" target="_blank">@bob-der-baumeister</a> and <a href="/profile/u3/jenny-rostock" class="mention" target="_blank">@jenny-rostock</a>.</p>' | ||
expect(extractMentionedUsers(content)).toEqual(['u2', 'u3']) | ||
}) | ||
|
||
describe('handles links', () => { | ||
it('with slug and id', () => { | ||
const content = | ||
'<p>Something inspirational about <a href="/profile/u2/bob-der-baumeister" class="mention" target="_blank">@bob-der-baumeister</a> and <a href="/profile/u3/jenny-rostock/" class="mention" target="_blank">@jenny-rostock</a>.</p>' | ||
expect(extractMentionedUsers(content)).toEqual(['u2', 'u3']) | ||
}) | ||
|
||
it('with domains', () => { | ||
const content = | ||
'<p>Something inspirational about <a href="http://localhost:3000/profile/u2/bob-der-baumeister" class="mention" target="_blank">@bob-der-baumeister</a> and <a href="http://localhost:3000//profile/u3/jenny-rostock/" class="mention" target="_blank">@jenny-rostock</a>.</p>' | ||
expect(extractMentionedUsers(content)).toEqual(['u2', 'u3']) | ||
}) | ||
|
||
it('special characters', () => { | ||
const content = | ||
'<p>Something inspirational about <a href="http://localhost:3000/profile/u!*(),2/bob-der-baumeister" class="mention" target="_blank">@bob-der-baumeister</a> and <a href="http://localhost:3000//profile/u.~-3/jenny-rostock/" class="mention" target="_blank">@jenny-rostock</a>.</p>' | ||
expect(extractMentionedUsers(content)).toEqual(['u!*(),2', 'u.~-3']) | ||
}) | ||
}) | ||
it('ignores links without .mention class', () => { | ||
expect(extractMentionedUsers(contentWithPlainLinks)).toEqual([]) | ||
}) | ||
|
||
describe('does not crash if', () => { | ||
it('`href` contains no user id', () => { | ||
const content = | ||
'<p>Something inspirational about <a href="/profile" class="mention" target="_blank">@bob-der-baumeister</a> and <a href="/profile/" class="mention" target="_blank">@jenny-rostock</a>.</p>' | ||
expect(extractMentionedUsers(content)).toEqual([]) | ||
}) | ||
describe('given a link with .mention class and `data-mention-id` attribute ', () => { | ||
it('extracts ids', () => { | ||
expect(extractMentionedUsers(contentWithMentions)).toEqual(['u3']) | ||
}) | ||
|
||
it('`href` is empty or invalid', () => { | ||
const content = | ||
'<p>Something inspirational about <a href="" class="mention" target="_blank">@bob-der-baumeister</a> and <a href="not-a-url" class="mention" target="_blank">@jenny-rostock</a>.</p>' | ||
expect(extractMentionedUsers(content)).toEqual([]) | ||
}) | ||
}) | ||
it('ignores empty `data-mention-id` attributes', () => { | ||
expect(extractMentionedUsers(contentEmptyMentions)).toEqual([]) | ||
}) | ||
}) | ||
}) |
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,26 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import minimatch from 'minimatch' | ||
|
||
let oEmbedProvidersFile = fs.readFileSync(path.join(__dirname, './providers.json'), 'utf8') | ||
// some providers allow a format parameter | ||
// we need JSON | ||
oEmbedProvidersFile = oEmbedProvidersFile.replace(/\{format\}/g, 'json') | ||
const oEmbedProviders = JSON.parse(oEmbedProvidersFile) | ||
|
||
export default function(embedUrl) { | ||
for (const provider of oEmbedProviders) { | ||
for (const endpoint of provider.endpoints) { | ||
const { schemes = [], url } = endpoint | ||
if (schemes.some(scheme => minimatch(embedUrl, scheme))) return url | ||
} | ||
const { hostname } = new URL(embedUrl) | ||
if (provider.provider_url.includes(hostname)) { | ||
const { | ||
endpoints: [{ url }], | ||
} = provider | ||
return url | ||
} | ||
} | ||
return null | ||
} |
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 findProvider from './findProvider' | ||
|
||
describe('Vimeo', () => { | ||
it('matches `https://vimeo.com/showcase/2098620/video/4082288`', () => { | ||
expect(findProvider('https://vimeo.com/showcase/2098620/video/4082288')).toEqual( | ||
'https://vimeo.com/api/oembed.json', | ||
) | ||
}) | ||
}) | ||
|
||
describe('RiffReporter', () => { | ||
it('matches `https://www.riffreporter.de/flugbegleiter-koralle/`', () => { | ||
expect(findProvider('https://www.riffreporter.de/flugbegleiter-koralle/')).toEqual( | ||
'https://www.riffreporter.de/service/oembed', | ||
) | ||
}) | ||
}) | ||
|
||
describe('Youtube', () => { | ||
it('matches `https://www.youtube.com/watch?v=qkdXAtO40Fo`', () => { | ||
expect(findProvider('https://www.youtube.com/watch?v=qkdXAtO40Fo')).toEqual( | ||
'https://www.youtube.com/oembed', | ||
) | ||
}) | ||
|
||
it('matches `https://youtu.be/qkdXAtO40Fo`', () => { | ||
expect(findProvider(`https://youtu.be/qkdXAtO40Fo`)).toEqual('https://www.youtube.com/oembed') | ||
}) | ||
|
||
it('matches `https://youtu.be/qkdXAtO40Fo?t=41`', () => { | ||
expect(findProvider(`https://youtu.be/qkdXAtO40Fo?t=41`)).toEqual( | ||
'https://www.youtube.com/oembed', | ||
) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this test just to give the edge case of non-alphanumeric characters in the URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I wanted to see if youtube shareable links with a time position
?t=41
cause troubles or not.