Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: kaiwu db load #917

Merged
merged 2 commits into from
Nov 11, 2024
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
20 changes: 15 additions & 5 deletions public_configs/fast-pr-url-rules.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const urlRules = [
const repoName = 'X-lab2017/open-digger-website';
const branch = 'master';
const platform = 'Github';
const horizontalRatio=0.95;
const verticalRatio=0.5;
let filePath = '';
if (!url.startsWith(baseUrl)) return null;
let i18n = null;
Expand All @@ -23,7 +25,7 @@ const urlRules = [
} else if (docPath.startsWith('blog/')) {
filePath = `${i18n != null ? `i18n/${i18n}docusaurus-plugin-content-` : ''}${docPath}/index.mdx`;
}
return { filePath, repoName, branch, platform };
return { filePath, repoName, branch, platform,horizontalRatio,verticalRatio };
},
tests: [
[
Expand Down Expand Up @@ -60,10 +62,12 @@ const urlRules = [
const repoName = 'X-lab2017/oss101-bok';
const branch = 'master';
const platform = 'Github';
const horizontalRatio=0.95;
const verticalRatio=0.5;
if (!url.startsWith(baseUrl)) return null;
const docPath = url.replace(baseUrl, '').split('#')[0];
const filePath = `docs/textbook/${docPath.slice(0, -1)}.md`;
return { filePath, repoName, branch, platform };
return { filePath, repoName, branch, platform,horizontalRatio,verticalRatio };
},
},
{
Expand All @@ -73,10 +77,12 @@ const urlRules = [
const repoName = 'wangyantong2000/docwebsite';
const branch = 'main';
const platform = 'Gitee';
const horizontalRatio=0.95;
const verticalRatio=0.5;
if (!url.startsWith(baseUrl)) return null;
const docPath = url.replace(baseUrl, '').split('#')[0];
const filePath = `docs/textbooks/${docPath}index.md`;
return { filePath, repoName, branch, platform };
return { filePath, repoName, branch, platform,horizontalRatio,verticalRatio };
},
},
{
Expand All @@ -86,12 +92,14 @@ const urlRules = [
const repoName = 'kaiyuanshe/oss-book';
const branch = 'main';
const platform = 'Github';
const horizontalRatio=0.95;
const verticalRatio=0.95;
if (!url.startsWith(baseUrl)) return null;
let docPath = url.replace(baseUrl, '').split('#')[0];
if (docPath.startsWith('slide')) return null;
docPath = docPath.replace('.html', '');
const filePath = `src/${docPath}.md`;
return { filePath, repoName, branch, platform };
return { filePath, repoName, branch, platform,horizontalRatio,verticalRatio };
},
tests: [
['https://kaiyuanshe.github.io/oss-book/Enterprise-and-Open-Source.html', 'src/Enterprise-and-Open-Source.md'],
Expand All @@ -110,6 +118,8 @@ const urlRules = [
const repoName = 'kwdb/docs';
let branch = 'master';
const platform = 'Gitee';
const horizontalRatio=0.95;
const verticalRatio=0.95;
if (!url.startsWith(baseUrl)) return null;
let docPath = url.replace(baseUrl, '').split('#')[0].replace('.html', '');
function extractVersion(str) {
Expand All @@ -132,7 +142,7 @@ const urlRules = [
}
}
const filePath = `${docPath}.md`;
return { filePath, repoName, branch, platform };
return { filePath, repoName, branch, platform,horizontalRatio,verticalRatio };
},
tests: [
[
Expand Down
40 changes: 32 additions & 8 deletions src/pages/ContentScripts/features/fast-pr/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { createRoot } from 'react-dom/client';
import features from '../../../../feature-manager';
import View from './view';
import { handleMessage } from './handleMessage';
import i18n from '../../../../helpers/i18n';
const featureId = features.getFeatureID(import.meta.url);
const t = i18n.t;
Expand All @@ -11,11 +10,28 @@ interface MatchedUrl {
repoName: string;
branch: string;
platform: string;
horizontalRatio: number;
verticalRatio: number;
}

const renderTo = (container: HTMLElement, filePath: string, repoName: string, branch: string, platform: string) => {
const renderTo = (
container: HTMLElement,
filePath: string,
repoName: string,
branch: string,
platform: string,
horizontalRatio: number,
verticalRatio: number
) => {
createRoot(container).render(
<View filePath={filePath} originalRepo={repoName} branch={branch} platform={platform} />
<View
filePath={filePath}
originalRepo={repoName}
branch={branch}
platform={platform}
horizontalRatio={horizontalRatio}
verticalRatio={verticalRatio}
/>
);
};

Expand All @@ -27,13 +43,21 @@ const init = async (matchedUrl: MatchedUrl | null) => {
if (matchedUrl) {
const container = document.createElement('div');
container.id = featureId;
renderTo(container, matchedUrl.filePath, matchedUrl.repoName, matchedUrl.branch, matchedUrl.platform);
renderTo(
container,
matchedUrl.filePath,
matchedUrl.repoName,
matchedUrl.branch,
matchedUrl.platform,
matchedUrl.horizontalRatio,
matchedUrl.verticalRatio
);
document.body.appendChild(container);
}
};
const observeUrlChanges = () => {
let lastUrl = window.location.href;
const observer = new MutationObserver(() => {
const checkUrlChange = () => {
const currentUrl = window.location.href;
if (currentUrl !== lastUrl) {
lastUrl = currentUrl;
Expand All @@ -46,13 +70,13 @@ const observeUrlChanges = () => {
iframe.contentWindow.postMessage({ command: 'matchUrl', url: currentUrl }, '*');
}
}
});

//Observe changes in the main body of the document
};
const observer = new MutationObserver(checkUrlChange);
observer.observe(document.body, {
childList: true,
subtree: true,
});
setInterval(checkUrlChange, 1000);
};

window.addEventListener('message', (event: MessageEvent) => {
Expand Down
8 changes: 5 additions & 3 deletions src/pages/ContentScripts/features/fast-pr/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ interface Props {
originalRepo: string;
branch: string;
platform: string;
horizontalRatio: number;
verticalRatio: number;
}
const View = ({ filePath, originalRepo, branch, platform }: Props) => {
const View = ({ filePath, originalRepo, branch, platform, horizontalRatio, verticalRatio }: Props) => {
const [giteeToken, setGiteeToken] = useState('');
const [githubToken, setGithubToken] = useState('');
const [options, setOptions] = useState<HypercrxOptions>(defaults);
Expand Down Expand Up @@ -128,8 +130,8 @@ const View = ({ filePath, originalRepo, branch, platform }: Props) => {

// Set the initial position to the middle-right of the screen when the component loads
useEffect(() => {
const initialX = window.innerWidth - buttonSize - padding; // 24px from the right of the screen
const initialY = window.innerHeight / 2 - buttonSize / 2; // Center vertically
const initialX = (window.innerWidth - buttonSize) * horizontalRatio;
const initialY = (window.innerHeight - buttonSize) * verticalRatio;
setPosition({ x: initialX, y: initialY });
}, []);
// Record the starting position when the mouse is pressed
Expand Down
Loading