allow embedding study URLs without a chapter ID
parent
ed260f6283
commit
0bb6ff71d9
|
@ -341,7 +341,10 @@ final class Study(
|
|||
|
||||
def embed(id: String, chapterId: String) =
|
||||
Action.async { implicit req =>
|
||||
env.study.api.byIdWithChapter(id, chapterId).map(_.filterNot(_.study.isPrivate)) flatMap {
|
||||
val studyWithChapter =
|
||||
if (chapterId == "autochap") env.study.api.byIdWithChapter(id)
|
||||
else env.study.api.byIdWithChapter(id, chapterId)
|
||||
studyWithChapter.map(_.filterNot(_.study.isPrivate)) flatMap {
|
||||
_.fold(embedNotFound) { case WithChapter(study, chapter) =>
|
||||
for {
|
||||
chapters <- env.study.chapterRepo.idNames(study.id)
|
||||
|
|
|
@ -64,10 +64,10 @@
|
|||
<string name="downloadGame">Download game</string>
|
||||
<string name="studyUrl">Study URL</string>
|
||||
<string name="currentChapterUrl">Current chapter URL</string>
|
||||
<string name="youCanPasteThisInTheForumToEmbed">You can paste this in the forum to embed</string>
|
||||
<string name="youCanPasteThisInTheForumToEmbed">You can paste this in the forum or your Lichess blog to embed</string>
|
||||
<string name="startAtInitialPosition">Start at initial position</string>
|
||||
<string name="startAtX">Start at %s</string>
|
||||
<string name="embedInYourWebsite">Embed in your website or blog</string>
|
||||
<string name="embedInYourWebsite">Embed in your website</string>
|
||||
<string name="readMoreAboutEmbedding">Read more about embedding</string>
|
||||
<string name="onlyPublicStudiesCanBeEmbedded">Only public studies can be embedded!</string>
|
||||
<string name="open">Open</string>
|
||||
|
|
|
@ -75,6 +75,8 @@ export function view(ctrl: StudyShareCtrl): VNode {
|
|||
chapter = ctrl.chapter();
|
||||
const isPrivate = ctrl.isPrivate();
|
||||
const addPly = (path: string) => (ctrl.withPly() ? `${path}#${ctrl.currentNode().ply}` : path);
|
||||
const youCanPasteThis = () =>
|
||||
h('p.form-help.text', { attrs: { 'data-icon': '' } }, ctrl.trans.noarg('youCanPasteThisInTheForumToEmbed'));
|
||||
return h('div.study__share', [
|
||||
h('div.downloads', [
|
||||
ctrl.cloneable
|
||||
|
@ -131,10 +133,10 @@ export function view(ctrl: StudyShareCtrl): VNode {
|
|||
['currentGameUrl', `${ctrl.relay.roundPath()}/${chapter.id}`],
|
||||
]
|
||||
: [
|
||||
['studyUrl', `/study/${studyId}`],
|
||||
['studyUrl', addPly(`/study/${studyId}`), true],
|
||||
['currentChapterUrl', addPly(`/study/${studyId}/${chapter.id}`), true],
|
||||
]
|
||||
).map(([i18n, path, isFull]: [string, string, boolean]) =>
|
||||
).map(([i18n, path, pastable]: [string, string, boolean]) =>
|
||||
h('div.form-group', [
|
||||
h('label.form-label', ctrl.trans.noarg(i18n)),
|
||||
h('input.form-control.autoselect', {
|
||||
|
@ -143,20 +145,7 @@ export function view(ctrl: StudyShareCtrl): VNode {
|
|||
value: `${baseUrl()}${path}`,
|
||||
},
|
||||
}),
|
||||
...(isFull
|
||||
? [
|
||||
fromPly(ctrl),
|
||||
!isPrivate
|
||||
? h(
|
||||
'p.form-help.text',
|
||||
{
|
||||
attrs: { 'data-icon': '' },
|
||||
},
|
||||
ctrl.trans.noarg('youCanPasteThisInTheForumToEmbed')
|
||||
)
|
||||
: null,
|
||||
]
|
||||
: []),
|
||||
...(pastable ? [fromPly(ctrl), !isPrivate ? youCanPasteThis() : null] : []),
|
||||
])
|
||||
),
|
||||
h(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import spinner from './component/spinner';
|
||||
|
||||
|
||||
function toYouTubeEmbedUrl(url: string) {
|
||||
if (!url) return;
|
||||
const m = url.match(
|
||||
|
@ -41,7 +42,8 @@ interface Group {
|
|||
|
||||
lichess.load.then(() => {
|
||||
const domain = window.location.host,
|
||||
studyRegex = new RegExp(domain + '/study/(?:embed/)?(\\w{8})/(\\w{8})(#\\d+)?\\b'),
|
||||
chapterRegex = new RegExp(domain + '/study/(?:embed/)?(\\w{8})/(\\w{8})(#\\d+)?\\b'),
|
||||
studyRegex = new RegExp(domain + '/study/(?:embed/)?(\\w{8})(#\\d+)?\\b'),
|
||||
gameRegex = new RegExp(domain + '/(?:embed/)?(\\w{8})(?:(?:/(white|black))|\\w{4}|)(#\\d+)?\\b'),
|
||||
notGames = ['training', 'analysis', 'insights', 'practice', 'features', 'password', 'streamer', 'timeline'];
|
||||
|
||||
|
@ -52,11 +54,17 @@ lichess.load.then(() => {
|
|||
type: 'youtube',
|
||||
src: yt,
|
||||
};
|
||||
let matches = a.href.match(studyRegex);
|
||||
if (matches && matches[2] && a.text.match(studyRegex))
|
||||
let matches = a.href.match(chapterRegex);
|
||||
if (matches && matches[2] && a.text.match(chapterRegex))
|
||||
return {
|
||||
type: 'study',
|
||||
src: '/study/embed/' + matches[1] + '/' + matches[2] + (matches[3] || ''),
|
||||
src: `/study/embed/${matches[1]}/${matches[2]}${matches[3] || ''}`,
|
||||
};
|
||||
matches = a.href.match(studyRegex);
|
||||
if (matches && matches[1] && a.text.match(studyRegex))
|
||||
return {
|
||||
type: 'study',
|
||||
src: `/study/embed/${matches[1]}/autochap${matches[2] || ''}`,
|
||||
};
|
||||
matches = a.href.match(gameRegex);
|
||||
if (matches && matches[1] && !notGames.includes(matches[1]) && a.text.match(gameRegex)) {
|
||||
|
|
Loading…
Reference in New Issue