Update OpenGraph metadata in subpages

Signed-off-by: Sebastian Martinez <sebastinez@me.com>
This commit is contained in:
Sebastian Martinez
2022-02-09 16:07:10 +01:00
committed by Alexis Sellier
parent 7b4c635c64
commit 1e827eb458
5 changed files with 30 additions and 4 deletions
+7 -1
View File
@@ -2,7 +2,7 @@
import type { Config } from "@app/config";
import type { BigNumber } from "@ethersproject/bignumber";
import { session } from "@app/session";
import { toWei } from "@app/utils";
import { setOpenGraphMetaTag, toWei } from "@app/utils";
import { formatEther } from "@ethersproject/units";
import { navigate } from "svelte-routing";
import { getMaxWithdrawAmount, lastWithdrawalByUser, calculateTimeLock } from "./lib";
@@ -14,6 +14,12 @@
let lastWithdrawal: BigNumber;
let error: string | undefined;
setOpenGraphMetaTag([
{ prop: "og:title", content: "Radicle Faucet" },
{ prop: "og:description", content: "Rinkeby Testnet Faucet" },
{ prop: "og:url", content: window.location.href }
]);
async function withdraw() {
const [state, message] = await isAbleToWithdraw(amount);
if (state === true) navigate("/faucet/withdraw", { state: { amount } });
+7
View File
@@ -6,9 +6,16 @@
import Loading from '@app/Loading.svelte';
import Message from '@app/Message.svelte';
import Cards from '@app/Cards.svelte';
import { setOpenGraphMetaTag } from '@app/utils';
export let config: Config;
setOpenGraphMetaTag([
{ prop: "og:title", content: "Radicle Interface" },
{ prop: "og:description", content: "Interact with Radicle" },
{ prop: "og:url", content: window.location.href }
]);
const getOrgs = config.orgs.pinned.length > 0
? Org.getMulti(config.orgs.pinned, config)
: Org.getAll(config);
+7
View File
@@ -7,9 +7,16 @@
import Loading from '@app/Loading.svelte';
import Message from '@app/Message.svelte';
import Cards from '@app/Cards.svelte';
import { setOpenGraphMetaTag } from '@app/utils';
export let config: Config;
setOpenGraphMetaTag([
{ prop: "og:title", content: "Radicle Orgs" },
{ prop: "og:description", content: "Orgs of the Radicle Network" },
{ prop: "og:url", content: window.location.href }
]);
const onCreate = () => modal = Create;
let modal: typeof SvelteComponent | null = null;
+7 -1
View File
@@ -6,7 +6,7 @@
import Avatar from '@app/Avatar.svelte';
import { Profile, ProfileType } from '@app/profile';
import type { ProjectInfo } from '@app/project';
import { formatOrg, formatSeedId, isRadicleId } from '@app/utils';
import { formatOrg, formatSeedId, isRadicleId, setOpenGraphMetaTag } from '@app/utils';
import { getOid } from '@app/project';
import { Seed } from '@app/base/seeds/Seed';
@@ -77,6 +77,12 @@
} else {
pageTitle = baseName;
}
setOpenGraphMetaTag([
{ prop: "og:title", content: projectInfo.name },
{ prop: "og:description", content: projectInfo.description },
{ prop: "og:url", content: window.location.href }
]);
}
function updateRouteParams({ detail: newParams }: { detail: { urn: string; path: string; revision: string; peer: string; content: proj.ProjectContent } }) {
+2 -2
View File
@@ -64,10 +64,10 @@ export async function toClipboard(text: string): Promise<void> {
return navigator.clipboard.writeText(text);
}
export function setOpenGraphMetaTag(data: {prop: string, content: string, attr?: string }[]): void {
export function setOpenGraphMetaTag(data: { prop: string; content: string; attr?: string }[]): void {
const elements = Array.from<HTMLElement>(document.querySelectorAll(`meta`));
elements.forEach((element: any) => {
let foundElement = data.find(data => {
const foundElement = data.find(data => {
return data.prop === element.getAttribute(data.attr || 'property');
});
if (foundElement) element.content = foundElement.content;