Add a file library in Google Drive for pages to link to
Tools → Media → Files uploads PDF, Office (.docx, .xlsx, .pptx), MP3, M4A and zip files, up to 50 MB, to the shared drive's Blog folder and shares each as anyone with the link can view (migration 048). A file's name and contents must agree. Content block links get "Choose a file" (paragraph, button and image links, list and link items, link cards). A link card also takes the file's name and Drive's picture of its first page, fetched after upload and saved into the image library; cards to Drive say "Google Drive". Deleting a file says first what still links to it. Setup and the nginx block: docs/google-drive-and-mail.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
36c9226bd9
commit
934598f954
13 changed files with 772 additions and 33 deletions
|
|
@ -56,6 +56,12 @@
|
|||
(LinkPreviewInput in MediaLibrary.tsx) that fills the row's empty
|
||||
title, blurb and image through `onPatch`.
|
||||
|
||||
`files: true` on a link field adds "Choose a file" (FilePicker in
|
||||
DriveFiles.tsx): the field takes the file's Drive link, and with
|
||||
`previewFills` (a link card) the row's empty title and picture take
|
||||
the file's name and first-page preview. `filesWhen` limits it to
|
||||
rows that match, as `when` does for the field.
|
||||
|
||||
`widget: "testNotice"` is a text box of email addresses with a
|
||||
"Send a test notice" button (TestNoticeInput below), for Site
|
||||
settings → Notices.
|
||||
|
|
@ -85,6 +91,7 @@ import { useRef, useState } from "react";
|
|||
import { ApiError, post } from "../../lib/api.ts";
|
||||
import ContentBlocks from "../ContentBlocks.tsx";
|
||||
import { ImageInput, LinkPreviewInput } from "./MediaLibrary.tsx";
|
||||
import { ChooseFileButton } from "./DriveFiles.tsx";
|
||||
|
||||
/* Live previews a collection can name with `preview`. Each gets the
|
||||
row as the form holds it, which is the API's shape. */
|
||||
|
|
@ -235,6 +242,17 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
|
|||
!list.some(([optionId]) => String(optionId) === String(value));
|
||||
}
|
||||
|
||||
// A file from the Drive library into this link field (`files`).
|
||||
const pickFile = (file) => {
|
||||
const fills = field.previewFills;
|
||||
const patch = { [field.path]: file.url };
|
||||
if (fills && !row?.[fills.title]) patch[fills.title] = file.title;
|
||||
if (fills && !row?.[fills.image] && file.preview) patch[fills.image] = file.preview;
|
||||
if (onPatch && !field.path.includes(".")) onPatch(patch);
|
||||
else onChange(file.url);
|
||||
};
|
||||
const showFiles = field.files && !locked && (!field.filesWhen || fieldShown({ when: field.filesWhen }, row));
|
||||
|
||||
const common = {
|
||||
id,
|
||||
className: `${input} ${error ? inputError : ""}`,
|
||||
|
|
@ -371,6 +389,11 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
|
|||
className={locked ? inputLocked : common.className}
|
||||
/>
|
||||
)}
|
||||
{showFiles && (
|
||||
<div className="mt-2">
|
||||
<ChooseFileButton value={value} onPick={pickFile} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue