Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ will not bring Algolia's changes into that package. Follow the
accessible name (including its header translations), and linked-image Markdown
rendering. Verify the behavior with the regression cases; keep unsafe URL
scheme rejection and HTML escaping intact.
- If all three fixes are included, return to the official package and retire the
custom build and override. Update packaging-specific tests while retaining
- Check for a supported completed-answer component in both the modal and
sidepanel so the site can preserve its optional tutorial video.
- If all three fixes and the answer component are supported, return to the
official package and retire the custom build and override. Update packaging-specific tests while retaining
the behavior checks.
- If a fix is still missing, update the custom build to the newer compatible
upstream release and retain only the fixes still needed. Refresh its source,
- If a fix or the slot still needs local support, update the custom build to the
newer compatible upstream release and retain the changes still needed. Refresh its source,
provenance, reviewed diff, version, packaged artifact, and lockfile together.

Keep related DocSearch packages compatible and run the
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ import video from '@site/src/data/css-anchor-tooltip-video.json';
<RecordedVideo video={video} showWatchLink />
```

Ask AI also uses the recording’s `watchPath` and `guidePath` to offer it
beside a relevant answer. Include the edition or section in `guidePath` when
it identifies which workflow the recording shows.

The next build generates the watch page, structured data, and video entry in
`/sitemap.xml`. The [release checks](README.md#tutorial-release-checks) discover
the guide and check the player, captions, links, duration, and sitemap against
Expand Down
7 changes: 7 additions & 0 deletions config/search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ encoded URLs, give the Ask AI dialog an accessible name, and render linked
screenshots safely. Do not edit installed
dependencies, intercept global networking, or rewrite rendered citations.

The modal and the sidepanel can show one optional recording below a completed
answer. The site matches its citations to published video definitions. A direct
watch link takes priority, followed by a matching guide section, edition, or
unambiguous guide. New recordings use the same catalog as the watch pages.
Check a Community-only answer, an unrelated answer, and keyboard playback in
both chat views when updating the integration.

After changing the dependency, test an absolute URL containing `%20` in both an
AI answer and its Sources menu; verify that it reaches the correct guide. Check
full-page Ask AI submission, keyboard close/focus restoration, and desktop/mobile
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"docusaurus": "docusaurus",
"test:tutorials": "node --test --test-reporter=tap scripts/tutorial-release.test.cjs",
"test:links": "node --test --test-reporter=tap scripts/verify-links.test.cjs",
"test:search": "node --test --test-reporter=tap scripts/search-tabs.test.cjs scripts/search-crawler.test.cjs scripts/docsearch-package.test.cjs scripts/tutorial-icons.test.cjs",
"test:search": "node --test --test-reporter=tap scripts/search-tabs.test.cjs scripts/search-crawler.test.cjs scripts/docsearch-package.test.cjs scripts/tutorial-icons.test.cjs scripts/ask-ai-video.test.mjs",
"package:tutorials": "node scripts/package-tutorials.cjs",
"verify:tutorials": "node scripts/verify-tutorials.cjs",
"verify:links": "node scripts/verify-links.cjs",
Expand All @@ -28,7 +28,7 @@
"dependencies": {
"@docsearch/css": "5.2.0",
"@docsearch/docusaurus-adapter": "5.2.0",
"@docsearch/react": "file:vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.2.tgz",
"@docsearch/react": "file:vendor/docsearch-react/releases/docsearch-react-5.2.0-phcode.3.tgz",
"@docusaurus/core": "3.10.2",
"@docusaurus/plugin-client-redirects": "3.10.2",
"@docusaurus/plugin-google-gtag": "3.10.2",
Expand Down
7 changes: 7 additions & 0 deletions plugins/tutorial-media/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ module.exports = function tutorialMediaPlugin({siteDir, baseUrl}, options) {
},
async contentLoaded({content, actions}) {
actions.setGlobalData({uploadDates: content.publications.videos});
// Only the Ask AI answer component imports this catalog. Media loads on demand.
const answerVideos = content.videos.map(({watchPath, guidePath, title, poster,
source, captions, width, height, metadata}) => ({
watchPath, guidePath, title, poster, source, captions, width, height,
seconds: Math.round(Number(metadata.duration.slice(2, -1))),
}));
await actions.createData('ask-ai-videos.json', JSON.stringify(answerVideos));
await Promise.all(content.videos.map(async video => {
const data = await actions.createData(`${path.basename(video.watchPath)}.json`, JSON.stringify(video));
actions.addRoute({
Expand Down
53 changes: 53 additions & 0 deletions scripts/ask-ai-video.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import assert from 'node:assert/strict';
import {test} from 'node:test';
import {fileURLToPath} from 'node:url';
import catalog from '../plugins/tutorial-media/watch-videos.js';
import {findAnswerVideo, prefersTextOnly} from '../src/components/SearchPageAskAi/find-answer-video.mjs';

const origin = 'https://docs.phcode.dev';
const videos = catalog.readWatchVideos(fileURLToPath(new URL('../', import.meta.url)));
const match = (...urls) => findAnswerVideo(videos, urls.map(url => ({url})), origin)?.watchPath;

test('every published watch page and edition or section-specific guide matches its recording', () => {
for (const video of videos) {
assert.equal(match(video.watchPath), video.watchPath);
assert.equal(match(origin + video.guidePath), video.watchPath);
}
});

test('one explicit watch link wins over guide links and repeated references', () => {
const watch = '/videos/add-image-phoenix-community';
assert.equal(match('/docs/tutorials/find-and-replace', watch + '/?ref=chat', watch), watch);
assert.equal(match('/docs/tutorials/add-images?edition=pro#turn-on-visual-editing',
'/docs/tutorials/add-images?edition=community#copy-your-picture'), '/videos/add-image-phoenix-pro');
});

test('distinguishes editions, operating systems and different tasks on the same page', () => {
assert.equal(match('/docs/tutorials/add-images?edition=community#copy-your-picture'), '/videos/add-image-phoenix-community');
assert.equal(match('/docs/tutorials/add-html-table#community-insert-table'), '/videos/add-html-table-phoenix-community');
assert.equal(match('/docs/startup-crash?source=help#linux'), '/videos/repair-phoenix-code-linux');
assert.equal(match('/docs/Features/find-in-files?edition=community'), '/videos/find-in-files');
assert.equal(match('/docs/tutorials/add-images'), undefined);
assert.equal(match('/docs/startup-crash'), undefined);
assert.equal(match('/docs/tutorials/image-text-layout?edition=community'), undefined);
assert.equal(match('/docs/tutorials/link-to-section#test-your-link'), undefined);
assert.equal(match('/docs/tutorials/add-html-table?edition=community#pro-insert-table'), undefined);
assert.equal(match('/docs/Features/keyboard-shortcuts'), undefined);
});

test('unknown media, malformed links and lookalike hosts cannot supply a player', () => {
for (const url of ['https://example.com/videos/find-in-files', '//example.com/videos/find-in-files',
'https://docs.phcode.dev.example.com/videos/find-in-files', 'https://user@docs.phcode.dev/videos/find-in-files',
'https://[', 'javascript:alert(1)', '/videos/missing', '/tutorials/media/find-in-files.mp4', '#windows']) {
assert.equal(match(url), undefined, url);
}
assert.equal(match('https://[', '/docs/Features/find-in-files#results'), '/videos/find-in-files');
assert.equal(findAnswerVideo(videos, [{url: '/videos/find-in-files'}], origin + '/').watchPath, '/videos/find-in-files');
});

test('respects plain-text requests and permits questions about text editing', () => {
for (const question of ['Text only, please.', 'Give me text-only instructions.', 'How do I add a photo without a video?']) {
assert.equal(prefersTextOnly(question), true);
}
assert.equal(prefersTextOnly('How can I find a text-only file?'), false);
});
21 changes: 21 additions & 0 deletions scripts/docsearch-package.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,29 @@ test('all DocSearch integrations use the integrity-locked package and the same R
assert.equal(createRequire(entry).resolve('react-dom'), require.resolve('react-dom'));
});

test('the optional answer component receives citations and stays empty without a site component or links', async () => {
const React = require('react');
const {renderToStaticMarkup} = require('react-dom/server');
const {AnswerContent, AnswerContentContext} = await import('@docsearch/react/answerContent');
const link = {url: '/videos/find-in-files'};
const question = 'How do I find text?';
function SiteContent(props) {
assert.deepEqual(props.links, [link]);
assert.equal(props.question, question);
return React.createElement('p', null, 'Optional recording');
}
const answer = links => React.createElement(AnswerContent, {links, question});
const withSite = links => React.createElement(AnswerContentContext.Provider, {value: SiteContent}, answer(links));
assert.equal(renderToStaticMarkup(answer([link])), '');
assert.equal(renderToStaticMarkup(withSite([])), '');
assert.equal(renderToStaticMarkup(withSite([link])), '<p>Optional recording</p>');
});

test('the installed artifact contains the reviewed source fixes', () => {
const expectedFiles = [
'src/AnswerContent.tsx',
'src/AskAiScreen.tsx',
'src/Sidepanel/ConversationScreen.tsx',
'src/utils/markdown.ts',
'src/utils/sanitize.ts',
'src/Sidepanel/Sidepanel.tsx',
Expand Down
4 changes: 3 additions & 1 deletion scripts/tutorial-release.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ async function fixture(t, publishedFiles = {}) {
await fs.mkdir(path.dirname(file), {recursive: true});
await fs.writeFile(file, 'Fixture: existence only; real media timing is verified after build.');
const slug = path.basename(file, '.mp4');
const video = {source, watchPath: '/videos/' + slug, captions: source.replace(/\.mp4$/, '.vtt')};
const video = {source, watchPath: '/videos/' + slug, captions: source.replace(/\.mp4$/, '.vtt'),
guidePath: '/docs/example', metadata: {duration: 'PT2S'}};
await fs.writeFile(path.join(siteDir, 'static', video.captions),
'WEBVTT\r\n\r\nNOTE editor note\r\n\r\nstep-one\r\n00:00.000 --> 00:02.000 align:start\r\n1. Open the\r\nproject.\r\n');
await fs.writeFile(path.join(siteDir, 'src/data', slug + '-video.json'), JSON.stringify(video));
Expand All @@ -69,6 +70,7 @@ test('first deployment assigns publication dates and saves the same dates used b
}});
assert.deepEqual(routes.map(route => route.path).sort(),
[pro, community].map(source => '/help/videos/' + path.basename(source, '.mp4')).sort());
assert.deepEqual(data.get('ask-ai-videos.json').map(video => video.seconds), [2, 2]);
for (const route of routes) {
const video = data.get(route.modules.video);
assert.equal(route.path, '/help' + video.watchPath);
Expand Down
58 changes: 58 additions & 0 deletions src/components/SearchPageAskAi/TutorialVideoAnswer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, {useId, useState} from 'react';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useBaseUrl from '@docusaurus/useBaseUrl';
import videos from '@generated/phoenix-tutorial-media/default/ask-ai-videos.json';
import {findAnswerVideo, prefersTextOnly} from './find-answer-video.mjs';
import styles from './TutorialVideoAnswer.module.css';

function VideoPreview({video}) {
const [open, setOpen] = useState(false);
const [failed, setFailed] = useState(false);
const playerId = useId();
const poster = useBaseUrl(video.poster);
const source = useBaseUrl(video.source);
const captions = useBaseUrl(video.captions);
const watchPage = useBaseUrl(video.watchPath);
const minutes = Math.floor(video.seconds / 60);
const duration = minutes ? `${minutes} min ${video.seconds % 60} sec` : `${video.seconds} sec`;
const action = open ? 'Hide video' : 'Play video';

return <div className={styles.preview}>
<button className={styles.toggle} type="button" aria-expanded={open} aria-controls={playerId}
onClick={() => {setFailed(false); setOpen(!open);}}>
<span className={styles.thumbnail} aria-hidden="true">
<img src={poster} alt="" loading="lazy" />
<span className={styles.icon}>
<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
{open ? <path d="m6 14 6-6 6 6" fill="none" stroke="currentColor" strokeWidth="2.5" /> :
<path d="M8 4.5v15l12-7.5z" fill="currentColor" />}
</svg>
</span>
</span>
<span className={styles.label}>
<strong>{video.title}</strong>
<span>{`${action} · ${duration}`}</span>
</span>
</button>
<div id={playerId} hidden={!open}>
{open && <>
{failed ? <p role="status" className={styles.error}>The video couldn’t load.</p> :
<video controls muted playsInline autoPlay width={video.width} height={video.height}
poster={poster} aria-label={video.title} onError={() => setFailed(true)}>
<source src={source} type="video/mp4" onError={() => setFailed(true)} />
<track kind="captions" src={captions} srcLang="en" label="English" />
</video>}
<a className={styles.watchLink} href={watchPage} target="_blank" rel="noopener noreferrer">
Video and transcript<span className="sr-only"> (opens in a new tab)</span>
</a>
</>}
</div>
</div>;
}

export default function TutorialVideoAnswer({links, question}) {
const origin = useDocusaurusContext().siteConfig.url;
if (prefersTextOnly(question)) return null;
const video = findAnswerVideo(videos, links, origin);
return video ? <VideoPreview key={video.watchPath} video={video} /> : null;
}
107 changes: 107 additions & 0 deletions src/components/SearchPageAskAi/TutorialVideoAnswer.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
.preview {
margin-block: .75rem .25rem;
color: var(--docsearch-text-color, var(--ifm-font-color-base));
}

.toggle {
display: flex;
align-items: center;
gap: .75rem;
width: 100%;
padding: .5rem;
background: transparent;
color: inherit;
border: 1px solid var(--ifm-color-emphasis-300);
border-radius: .5rem;
font: inherit;
text-align: start;
cursor: pointer;
}

.toggle:hover {
background: var(--ifm-hover-overlay);
}

.thumbnail {
position: relative;
flex: 0 0 5rem;
aspect-ratio: 8 / 5;
overflow: hidden;
border-radius: .25rem;
background: var(--ifm-color-emphasis-200);
}

.thumbnail img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}

.icon {
position: absolute;
inset: 0;
margin: auto;
display: grid;
place-items: center;
width: 1.75rem;
height: 1.75rem;
border-radius: 50%;
color: white;
background: rgb(0 0 0 / 78%);
}

.label {
display: grid;
gap: .125rem;
min-width: 0;
line-height: 1.35;
overflow-wrap: anywhere;
}

.label strong {
font-size: .9375rem;
}

.label > span, .watchLink {
font-size: .8125rem;
}

.label > span {
color: var(--ifm-color-content-secondary);
}

.preview video {
display: block;
width: 100%;
height: auto;
max-height: 52vh;
margin-block-start: .375rem;
border-radius: .375rem;
background: black;
}

.watchLink {
display: inline-flex;
align-items: center;
min-height: 32px;
color: var(--ifm-color-primary-darkest);
text-decoration: underline;
}

[data-theme='dark'] .watchLink {
color: var(--ifm-color-primary);
}

.watchLink:hover {
color: var(--ifm-font-color-base);
}

.toggle:focus-visible, .watchLink:focus-visible {
outline: 2px solid var(--docsearch-primary-color, var(--ifm-color-primary));
outline-offset: 2px;
}

.error {
margin: .5rem 0 0;
}
Loading