Skip to content

Commit

Permalink
feat: add sharepoint integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Ellison committed Jul 4, 2023
1 parent 3da363c commit e7c8467
Show file tree
Hide file tree
Showing 12 changed files with 548 additions and 507 deletions.
2 changes: 1 addition & 1 deletion components/content/IndexView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function IndexView({
url={c?.file}
image={
c?.frontmatter?.image
? `/api/content/${siteConfig.content.providers.owner}/${siteConfig.content.providers.repo}?path=${path.dirname(c.file)}/${c.frontmatter.image}&branch=${siteConfig.content.providers.branch}`
? `/api/content/github/${siteConfig.content.providers.owner}/${siteConfig.content.providers.repo}?path=${path.dirname(c.file)}/${c.frontmatter.image}&branch=${siteConfig.content.providers.branch}`
: null
}
/>
Expand Down
2 changes: 1 addition & 1 deletion components/services/IndexView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function IndexView({
<Container maxWidth="lg" sx={{ height: '100vh', mt: '10%' }}>
<Grid container spacing={4} alignItems="stretch">
{providers ? (
providers.map((c, i) => <Tile key={i} name={c?.frontmatter?.title} url={c?.file} image={`/api/content/${siteConfig.content.providers.owner}/${siteConfig.content.providers.repo}?path=${path.dirname(c?.file)}/${c?.frontmatter?.image}&branch=${siteConfig.content.providers.branch}`} simage={c?.frontmatter?.image} />)
providers.map((c, i) => <Tile key={i} name={c?.frontmatter?.title} url={c?.file} image={`/api/content/github/${siteConfig.content.providers.owner}/${siteConfig.content.providers.repo}?path=${path.dirname(c?.file)}/${c?.frontmatter?.image}&branch=${siteConfig.content.providers.branch}`} simage={c?.frontmatter?.image} />)
) : (
null
)}
Expand Down
2 changes: 1 addition & 1 deletion components/solutions/IndexView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function IndexView({
<Container maxWidth="lg" sx={{ height: '100vh', mt: '10%' }}>
{/* <Grid container spacing={4} alignItems="stretch">
{providers ? (
providers.map((c, i) => <Tile key={i} name={c?.frontmatter?.title} url={c?.file} image={`/api/content/${siteConfig.content.providers.owner}/${siteConfig.content.providers.repo}?path=${path.dirname(c?.file)}/${c?.frontmatter?.image}&branch=${siteConfig.content.providers.branch}`} simage={c?.frontmatter?.image} />)
providers.map((c, i) => <Tile key={i} name={c?.frontmatter?.title} url={c?.file} image={`/api/content/github/${siteConfig.content.providers.owner}/${siteConfig.content.providers.repo}?path=${path.dirname(c?.file)}/${c?.frontmatter?.image}&branch=${siteConfig.content.providers.branch}`} simage={c?.frontmatter?.image} />)
) : (
null
)}
Expand Down
79 changes: 48 additions & 31 deletions constants/mdxProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { ProgressTable } from '../components/Tables.jsx';
// import {Layout, Column, Item } from './Layouts';

import path from 'path';
import { Dialog, DialogContent, DialogActions, Button, IconButton, Box, Typography, Alert} from '@mui/material';
import { Dialog, DialogContent, DialogActions, Button, IconButton, Box, Typography, Alert } from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';


Expand All @@ -48,26 +48,32 @@ import CloseIcon from '@mui/icons-material/Close';
function MdxImage({ props, baseContext }) {
let src = props.src;

if (baseContext.source === 'local' && baseContext.router.asPath && src.slice(0, 2) === './') { // relative
src = src.replace('./', '/');
src = '/api/files/get-binary?filePath=' + baseContext.router.asPath + src;
} else if (baseContext.source === 'local' && baseContext.router.asPath && src.slice(0, 1) === '/') { //file is an absolute path (public directory)
src = src
} else if (baseContext.source === 'github') {
// strip off leading / if present
src = src.replace('./', '');
if (src.slice(0, 1) === '/') { src = src.slice(1) };
// get directory from the file path
let dir = path.dirname(baseContext.file)
src = dir + '/' + src;

src = '/api/content/' + baseContext.owner + '/' + baseContext.repo + '?path=' + src + '&branch=' + baseContext.branch;
if (isSharePointUrl(src)) {
src = '/api/content/sharepoint?url=' + src

} else {
src = '/image-not-found.png';
};


if (baseContext.source === 'local' && baseContext.router.asPath && src.slice(0, 2) === './') { // relative
src = src.replace('./', '/');
src = '/api/files/get-binary?filePath=' + baseContext.router.asPath + src;
} else if (baseContext.source === 'local' && baseContext.router.asPath && src.slice(0, 1) === '/') { //file is an absolute path (public directory)
src = src
} else if (baseContext.source === 'github') {
// strip off leading / if present
src = src.replace('./', '');
if (src.slice(0, 1) === '/') { src = src.slice(1) };
// get directory from the file path
let dir = path.dirname(baseContext.file)
src = dir + '/' + src;

src = '/api/content/github/' + baseContext.owner + '/' + baseContext.repo + '?path=' + src + '&branch=' + baseContext.branch;

} else {
src = '/image-not-found.png';
};

};
// Custom hook for getting window size
function useWindowSize() {
const [size, setSize] = useState([0, 0]);
Expand All @@ -85,7 +91,7 @@ function MdxImage({ props, baseContext }) {
function useContainerSize() {
const ref = useRef(null);
const [size, setSize] = useState({ width: 0, height: 0 });

useEffect(() => {
function updateSize() {
setSize({
Expand All @@ -95,7 +101,7 @@ function MdxImage({ props, baseContext }) {
}
window.addEventListener('resize', updateSize);
updateSize();

return () => window.removeEventListener('resize', updateSize);
}, []);
// console.log('useContainerSize:size', size)
Expand All @@ -106,7 +112,7 @@ function MdxImage({ props, baseContext }) {

function ImageComponent({ src, alt }) {



const [open, setOpen] = useState(false);
const [width, height] = useWindowSize();
Expand All @@ -127,12 +133,12 @@ function MdxImage({ props, baseContext }) {
const { naturalWidth, naturalHeight } = event.target;
setImageSize({ width: naturalWidth, height: naturalHeight });
};

return (
<>

<Box
ref={containerRef}
ref={containerRef}
sx={{
display: 'flex',
alignItems: 'center',
Expand All @@ -159,20 +165,20 @@ function MdxImage({ props, baseContext }) {
fullWidth={true}
maxWidth="90%"
>
<DialogActions>
<IconButton color="highlight" onClick={handleClose}>
<CloseIcon />
</IconButton>
</DialogActions>
<DialogActions>
<IconButton color="highlight" onClick={handleClose}>
<CloseIcon />
</IconButton>
</DialogActions>

<DialogContent sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
margin: 'auto'
}}>
<img src={src} alt={alt}/>
<img src={src} alt={alt} />
</DialogContent>
</Dialog>
</>
Expand Down Expand Up @@ -247,10 +253,21 @@ export const mdComponents = (baseContext) => ({
// Font,
// layouts
TitleSlide,
Layout: (props) => null,
Layout: (props) => null,
Column, Item
});

// export default ({ children }) => (
// <MDXProvider components={mdComponents}>{children}</MDXProvider>
// );


function isSharePointUrl(url) {
try {
const urlObj = new URL(url);
const hostname = urlObj.hostname;
return hostname.endsWith('sharepoint.com');
} catch {
return false;
}
}
Loading

0 comments on commit e7c8467

Please sign in to comment.