Skip to content

Commit 7d83a28

Browse files
committed
KTL-2944 feat: add the youtube playlist
1 parent 5343558 commit 7d83a28

File tree

9 files changed

+120
-8
lines changed

9 files changed

+120
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ generated
5050

5151
/reports*
5252
/data/page_views_map.json
53+
.peer-deps-installed

.npmrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
save-exact = true
1+
save-exact = true
2+
3+
@webteam:registry=https://packages.jetbrains.team/npm/p/wt/npm/

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ You can:
139139
140140
## Local development
141141
142+
### For internal contributors
143+
Use a VPN or the office network for development, if possible. Otherwise, see below.
144+
145+
### For external contributors
146+
To build the website locally without corporate network access, set the following environment variable:
147+
148+
`export USE_FALLBACK_FOR_INTERNAL_PACKAGES=1`
149+
150+
This will allow the project to build, but some UI components will not be displayed because they are available only within the corporate network.
151+
142152
#### preliminaries: python3 installed
143153
144154
```

blocks/server-side/additional-materials/additional-materials.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import cn from 'classnames';
55
import styles from './additional-materials.module.css';
66
import { useTextStyles } from '@rescui/typography';
77

8-
import YoutubePlayer from '@jetbrains/kotlin-web-site-ui/out/components/youtube-player';
8+
// @ts-ignore
9+
import YoutubePlaylist from '@webteam/youtube-playlist/lib';
910

1011
export const AdditionalMaterials: FC = ({}) => {
1112

@@ -25,11 +26,10 @@ export const AdditionalMaterials: FC = ({}) => {
2526
</h3>
2627

2728
<div className="ktl-row">
28-
<div className="ktl-col-12 ktl-col-md-8">
29-
<YoutubePlayer
30-
mode={1}
31-
id="PLlFc5cFwUnmx-dpq9nkdaVJX0GnrM1Mp1"
32-
previewImgSrc="https://img.youtube.com/vi/0URxGa3q3tY/maxresdefault.jpg"
29+
<div className="ktl-col-12">
30+
<YoutubePlaylist
31+
playlistId="PLlFc5cFwUnmx-dpq9nkdaVJX0GnrM1Mp1"
32+
playlistTitle="Server-Side Development with Kotlin"
3333
/>
3434
</div>
3535
</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
export const WebteamFallback = () => {
4+
return <div>The component is not availalble without VPN</div>;
5+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { FC } from 'react';
2+
3+
import YoutubePlayer from '@jetbrains/kotlin-web-site-ui/out/components/youtube-player';
4+
5+
interface YoutubePlaylistProps {
6+
playlistId: string;
7+
playlistTitle: string;
8+
}
9+
10+
const YoutubePlaylist: FC<YoutubePlaylistProps> = ({ playlistId, playlistTitle }) => {
11+
return (
12+
<YoutubePlayer
13+
mode={1}
14+
id={playlistId}
15+
/>
16+
);
17+
};
18+
19+
export default YoutubePlaylist;

next.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require('path');
12
const packageJSON = require('./package.json');
23

34
const withPlugins = require('next-compose-plugins');
@@ -13,6 +14,20 @@ let transpiledPackages = [
1314
'@rescui/menu'
1415
];
1516

17+
if (process.env.USE_FALLBACK_FOR_INTERNAL_PACKAGES !== '1') {
18+
transpiledPackages.push(
19+
'@webteam/youtube-playlist',
20+
'@webteam/ui-contexts',
21+
'@webteam/colors',
22+
'@webteam/toggle',
23+
'@webteam/youtube-player',
24+
'@webteam/use-fetch',
25+
'@webteam/use-async-data',
26+
'@webteam/bem-cn-fast',
27+
'@webteam/list'
28+
)
29+
}
30+
1631
const withTranspile = nextTranspileModules(transpiledPackages);
1732

1833
const nextConfig = {
@@ -44,6 +59,17 @@ const nextConfig = {
4459
type: 'asset/source'
4560
});
4661

62+
const useFallbackForInternalPackages = process.env.USE_FALLBACK_FOR_INTERNAL_PACKAGES === '1';
63+
64+
config.resolve.alias = config.resolve.alias || {};
65+
66+
if (useFallbackForInternalPackages) {
67+
config.resolve.alias['@webteam'] = path.resolve(
68+
__dirname,
69+
'components/webteam-fallback'
70+
);
71+
}
72+
4773
return config;
4874
},
4975
};

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,21 @@
107107
"webpack-dev-server": "^4.3.1",
108108
"yaml-loader": "0.7.0"
109109
},
110+
"webteamDependencies": {
111+
"@webteam/ui-contexts": "0.10.10",
112+
"@webteam/youtube-playlist": "1.8.3"
113+
},
110114
"resolutions": {
111115
"sharp": "^0.28.3"
112116
},
117+
"overrides": {
118+
"sharp": "^0.28.3"
119+
},
113120
"scripts": {
114121
"build": "yarn run build:production && yarn run next-build-static",
115122
"build:production": "NODE_ENV=production webpack --mode production",
116-
"postinstall": "cd node_modules/codemirror && rollup -c",
123+
"install:internal": "node scripts/install-internal.js",
124+
"postinstall": "npm run install:internal && cd node_modules/codemirror && rollup -c",
117125
"start": "webpack serve",
118126
"next-dev": "next dev",
119127
"next-build-static": "next build && next export",

scripts/install-internal.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { execSync } = require('child_process');
4+
const flagFile = path.join(process.cwd(), '.peer-deps-installed');
5+
6+
if (fs.existsSync(flagFile)) {
7+
console.log('Peer dependencies already installed, skipping...');
8+
fs.rmSync(flagFile);
9+
process.exit(0);
10+
}
11+
12+
try {
13+
const pkgPath = path.join(process.cwd(), 'package.json');
14+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
15+
const peerDeps = pkg.webteamDependencies || {};
16+
17+
if (Object.keys(peerDeps).length === 0) {
18+
console.log('No optional peer dependencies to install.');
19+
process.exit(0);
20+
}
21+
22+
if (process.env.USE_FALLBACK_FOR_INTERNAL_PACKAGES === '1') {
23+
console.log('No external packages are installed, using fallback.');
24+
process.exit(0);
25+
}
26+
27+
const packagesToInstall = Object.entries(peerDeps)
28+
.map(([name, version]) => `${name}@${version.replace(/"/g, '')}`)
29+
.join(' ');
30+
31+
console.log(`Installing ${packagesToInstall} as optional peer dependencies...`);
32+
33+
execSync(`npm install --no-package-lock --no-save --legacy-peer-deps ${packagesToInstall}`, { stdio: 'inherit' });
34+
35+
fs.writeFileSync(flagFile, new Date().toISOString());
36+
37+
console.log('Peer dependencies installed successfully.');
38+
} catch (err) {
39+
console.error('Failed to install peer dependencies:', err.message);
40+
process.exit(1);
41+
}

0 commit comments

Comments
 (0)