Skip to content

Commit

Permalink
feat: implement multiple type url
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH committed Feb 4, 2024
1 parent c826f88 commit 5dfa8ff
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logseq-plugin-template-react",
"version": "1.0.0",
"name": "logseq-gallery",
"version": "1.0.1",
"main": "dist/index.html",
"scripts": {
"dev": "vite",
Expand Down
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ Implement a gallery renderer for Logseq. like Notion
{{renderer :gallery, <page query>, <title>}}
```

![](./imgs/screenshot.png)
![](./imgs/screenshot.png)

the Note should have `cover` or `banner` property.
for example:
`cover:: ../assets/IMG_2694_1706277077580_0.jpeg`

and the url is compatible with file path(`../assets/IMG_2694_1706277077580_0.jpeg`) and markdown url(`![untitle](../assets/IMG_2694_1706277077580_0.jpeg)`).
24 changes: 19 additions & 5 deletions src/App.tsx → src/Gallery.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import { PageEntity } from "@logseq/libs/dist/LSPlugin";
import React from "react";


function processCoverURL(rawCoverURL: string): string {
const markdownImageRegex = /!\[.*\]\((.*)\)/;
const matches = rawCoverURL.match(markdownImageRegex);
if (matches && matches.length > 1) {
return matches[1];
}
return rawCoverURL;
}

interface NoteProps {
page: PageEntity
graphPath:string
}
const Note = ({page,graphPath}:NoteProps) => {

const coverURL = page.properties?.cover || page.properties?.banner
const propsBanner = encodeURI("assets://" + graphPath + coverURL.replace("..", ""))
const rawCoverURL = page.properties?.cover || page.properties?.banner

// replace markdown image path to assert path if it is
// to judge if it is a markdown image path like ![xxx](path)

const propsBanner = encodeURI("assets://" + graphPath + processCoverURL(rawCoverURL).replace("..", ""))

return (
<div className="w-48 whitespace-nowrap rounded-lg cursor-pointer overflow-hidden"
Expand Down Expand Up @@ -37,12 +51,12 @@ const Note = ({page,graphPath}:NoteProps) => {
)
}

interface AppProps {
interface GalleryProps {
pages: PageEntity[]
graphPath:string
title: string
}
function App({pages,graphPath,title}:AppProps) {
function Gallery({pages,graphPath,title}:GalleryProps) {
return (
<main>
<h3>{title}</h3>
Expand All @@ -61,4 +75,4 @@ function App({pages,graphPath,title}:AppProps) {

}

export default App;
export default Gallery;
4 changes: 2 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from "react";
import "./index.css";

import { logseq as PL } from "../package.json";
import App from "./App";
import Gallery from "./Gallery";
import { PageEntity } from "@logseq/libs/dist/LSPlugin";


Expand All @@ -26,7 +26,7 @@ function main() {
const pages = await logseq.DB.q(query) as PageEntity[]
const graphPath = (await logseq.App.getCurrentGraph())?.path || "";

const html = renderToString(<App pages={pages} graphPath={graphPath} title={title}/>)
const html = renderToString(<Gallery pages={pages} graphPath={graphPath} title={title}/>)
logseq.provideUI({
key: 'h1-playground',
slot,
Expand Down

0 comments on commit 5dfa8ff

Please sign in to comment.