Skip to content

Commit

Permalink
Misc. page fixes (#114)
Browse files Browse the repository at this point in the history
* Display "Save" instead of "Edit" when editing

* Fix allowed schemes when rendering links

* Display title when visiting main group pages

* Remove scheme from notifier URLs
  • Loading branch information
GAsplund authored Aug 22, 2024
1 parent 33d7a37 commit 6c6b527
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 11 deletions.
20 changes: 20 additions & 0 deletions src/app/(groups)/[locale]/groups/[id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,29 @@ import TopLoader from '@/components/TopLoader/TopLoader';
import ToastContainerWrapper from '@/components/ToastContainerWrapper/ToastContainerWrapper';
import DivisionGroupService from '@/services/divisionGroupService';
import GammaService from '@/services/gammaService';
import { Metadata } from 'next';
import i18nService from '@/services/i18nService';

const poppins = Poppins({ weight: ['400'], subsets: ['latin'] });

export async function generateMetadata({
params: { locale, id }
}: {
params: { locale: string; id: string };
}) {
const group = await DivisionGroupService.getInfoBySlug(id).catch(() => {
return null;
});
const l = i18nService.getLocale(locale);
return {
title:
group !== null
? group.prettyName + ' - ' + l.site.siteTitle
: l.site.siteTitle,
description: l.site.siteDescription
} as Metadata;
}

export const dynamicParams = false;

export default async function RootLayout({
Expand Down
2 changes: 1 addition & 1 deletion src/components/DivisionPageForm/DivisionPageForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ const DivisionPageForm = (divisionPost: DivisionPostFormProps) => {
<div className={styles.actions}>
<ActionButton onClick={apply}>
{divisionPost.editedId !== undefined
? l.general.edit
? l.general.save
: l.general.create}
</ActionButton>
<ActionButton onClick={preview}>Förhandsgranska</ActionButton>
Expand Down
12 changes: 9 additions & 3 deletions src/components/MarkdownView/MarkdownView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { marked } from 'marked';
import style from './MarkdownView.module.scss';
import sanitizeHtml from 'sanitize-html';

const customAllowedTags = sanitizeHtml.defaults.allowedTags.concat(['img']);
const customAllowedSchemes = sanitizeHtml.defaults.allowedSchemes.concat([
'blob'
]);

const MarkdownView = ({
content,
allowBlob = false
Expand All @@ -18,10 +23,11 @@ const MarkdownView = ({
const renderMarkdownText = () => {
const rawMarkup = marked.parse(content) as string;
const sanitizedMarkup = sanitizeHtml(rawMarkup, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
allowedTags: customAllowedTags,
disallowedTagsMode: 'escape',
allowedSchemes:
allowBlob && sanitizeHtml.defaults.allowedSchemes.concat(['blob'])
allowedSchemes: allowBlob
? customAllowedSchemes
: sanitizeHtml.defaults.allowedSchemes
});
return { __html: sanitizedMarkup };
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/NewsPostForm/NewsPostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ const NewsPostForm = (newsPost: NewPostFormProps) => {
<br />
<div className={style.actions}>
<ActionButton onClick={send}>
{newsPost.id !== undefined ? l.general.edit : l.general.create}
{newsPost.id !== undefined ? l.general.save : l.general.create}
</ActionButton>
<ActionButton onClick={preview}>{l.editor.previewAction}</ActionButton>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/PageForm/PageForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const PageForm = (description: NewPostFormProps) => {
<br />
<div className={styles.actions}>
<ActionButton onClick={send}>
{description.id !== undefined ? l.general.edit : l.general.create}
{description.id !== undefined ? l.general.save : l.general.create}
</ActionButton>
<ActionButton onClick={preview}>{l.editor.previewAction}</ActionButton>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/dictionaries/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"download": "Download",
"upload": "Upload",
"uploaded": "Uploaded",
"close": "Close"
"close": "Close",
"save": "Save"
},
"site": {
"siteTitle": "IT at Chalmers",
Expand Down
3 changes: 2 additions & 1 deletion src/dictionaries/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"download": "Ladda ner",
"upload": "Ladda upp",
"uploaded": "Uppladdad",
"close": "Stäng"
"close": "Stäng",
"save": "Spara"
},
"site": {
"siteTitle": "IT på Chalmers",
Expand Down
6 changes: 3 additions & 3 deletions src/services/notifyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DiscordWebhookNotifier implements Notifier {
embeds: [
{
title: title,
url: `http://${process.env.BASE_URL || 'localhost:3000'}/post/${
url: `${process.env.BASE_URL ?? 'http://localhost:3000'}/post/${
post.id
}`,
description: content,
Expand Down Expand Up @@ -145,8 +145,8 @@ class SlackWebhookNotifier implements Notifier {
type: 'section',
text: {
type: 'mrkdwn',
text: `*<http://${
process.env.BASE_URL || 'localhost:3000'
text: `*<${
process.env.BASE_URL ?? 'http://localhost:3000'
}/post/${post.id}|${title}>*`
}
},
Expand Down

0 comments on commit 6c6b527

Please sign in to comment.