Skip to content

Commit

Permalink
fix: resolve image urls relative to template repository url
Browse files Browse the repository at this point in the history
  • Loading branch information
TheChristophe committed Sep 20, 2023
1 parent 1deb37f commit d7923c6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend
Submodule backend updated from a52272 to f180f7
1 change: 1 addition & 0 deletions docker-compose.base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
NEXT_PUBLIC_OAUTH_AUTHORITY: ${OAUTH_AUTHORITY}
NEXT_PUBLIC_OIDC_REDIRECT_HOST: ${FRONTEND_REDIRECT_HOST}
NEXT_PUBLIC_OIDC_CLIENT_ID: ${FRONTEND_OIDC_CLIENT_ID}
NEXT_PUBLIC_TEMPLATE_REPOSITORY: ${REPOSITORY_URL}
labels:
traefik.http.routers.webapp.rule: Host(`${DOMAIN}`)

Expand Down
1 change: 1 addition & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
OAUTH_AUTHORITY: ${OAUTH_AUTHORITY}
OIDC_REDIRECT_HOST: ${FRONTEND_REDIRECT_HOST}
OIDC_CLIENT_ID: ${FRONTEND_OIDC_CLIENT_ID}
REPOSITORY_URL: ${REPOSITORY_URL}
labels:
traefik.http.routers.webapp.tls: true
traefik.http.routers.webapp.tls.certResolver: letsEncrypt
Expand Down
2 changes: 2 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ ARG OIDC_REDIRECT_HOST
ENV FRONTEND_REDIRECT_HOST=${OIDC_REDIRECT_HOST}
ARG OIDC_CLIENT_ID
ENV FRONTEND_OIDC_CLIENT_ID=${OIDC_CLIENT_ID}
ARG REPOSITORY_URL
ENV NEXT_PUBLIC_TEMPLATE_REPOSITORY=${REPOSITORY_URL}

RUN yarn build

Expand Down
7 changes: 6 additions & 1 deletion frontend/components/templates/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Template as TemplateDto } from 'lib/client/models/template';
import Link from 'next/link';
import Badge from 'components/Badge';
import Rating from 'components/Rating';
import resolveImage from 'lib/resolveImage';

type TemplateProps = {
template: TemplateDto;
Expand All @@ -30,7 +31,11 @@ const Template: FC<TemplateProps> = ({ template }) => {
</div>
{template.picture && (
<div className="flex-grow-0 flex justify-center items-center">
<img src={template.picture} alt="" className="max-w-[100px]" />
<img
src={resolveImage(template.picture)}
alt=""
className="max-w-[100px]"
/>
</div>
)}
</div>
Expand Down
9 changes: 9 additions & 0 deletions frontend/lib/resolveImage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// TODO: only works with github repos, maybe gitlab
const resolveImage = (relativeUrl: string) => {
return `${
process.env['NEXT_PUBLIC_TEMPLATE_REPOSITORY']?.replace('.git', '') ??
'https://github.com/m-team-kit/templates-hub.git'
}/raw/main/${relativeUrl}`;
};

export default resolveImage;
6 changes: 5 additions & 1 deletion frontend/pages/template/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import TemplateForm from 'components/TemplateForm';
import Rating from 'components/Rating';
import { Code2 } from 'lucide-react';
import ErrorBox from 'components/ErrorBox';
import resolveImage from 'lib/resolveImage';

// TODO: SSR?
const Template: NextPage = () => {
Expand Down Expand Up @@ -89,7 +90,10 @@ const Template: NextPage = () => {
</div>
<div className="flex-grow-0">
{template.data.data.picture && (
<img src={template.data.data.picture} alt="template picture" />
<img
src={resolveImage(template.data.data.picture)}
alt="template picture"
/>
)}
</div>
</div>
Expand Down

0 comments on commit d7923c6

Please sign in to comment.