Replies: 6 comments 31 replies
-
wow, this is cool, out of my imagination. Is it possible to adapt itself to the light/dark mode? |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to do the same with a block as book and the cover as block-property value? |
Beta Was this translation helpful? Give feedback.
-
Just updated the view: it should nicely display glass card for any DARK theme |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hello, I've designed a new card template, but I've found that the rendering result does not meet my expectations. <style>
#``c.identity.slot`` body {
font-family: 'Arial', sans-serif;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
#``c.identity.slot`` .ticket {
position: relative;
width: 100%;
max-width: 520px;
border-radius: 10px;
padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
#``c.identity.slot`` .ticket-number {
font-size: 24px;
font-weight: bold;
color: red;
}
#``c.identity.slot`` .station {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 20px;
margin: 10px 0;
}
#``c.identity.slot`` .arrow {
margin: 0 10px;
font-size: 24px;
}
#``c.identity.slot`` .date-train {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin: 10px 0;
}
#``c.identity.slot`` .additional-info {
font-size: 14px;
margin: 10px 0;
}
#``c.identity.slot`` .bottom-section {
display: flex;
justify-content: space-between;
border-top: 1px solid #ccc;
padding-top: 10px;
margin-top: 10px;
}
#``c.identity.slot`` .qr-code {
width: 46px;
height: 46px;
}
#``c.identity.slot`` .barcode {
margin-top: 10px;
height: 24px;
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=');
background-repeat: repeat-x;
}
</style>
``{_
var mode = c.args.block ? 'block' : 'page'
var title = when(c.args.title, dev.get(mode + c.args.title) || c.args.title)
var info1 = when(c.args.info1, dev.get(mode + c.args.info1) || c.args.info1)
var info2 = when(c.args.info2, dev.get(mode + c.args.info2) || c.args.info2)
var info3 = when(c.args.info3, dev.get(mode + c.args.info3) || c.args.info3)
var markup = when(c.args.cover, dev.get(mode + c.args.cover) || c.args.cover)
var ref_link = when(c.args.ref_link, dev.get(mode + c.args.ref_link) || c.args.ref_link)
function createElement(tag, attributes, ...children) {
const element = document.createElement(tag);
for (const key in attributes) {
if (key.startsWith('on')) {
element.addEventListener(key.substring(2).toLowerCase(), attributes[key]);
} else {
element.setAttribute(key, attributes[key]);
}
}
children.forEach(child => {
if (typeof child === 'string') {
element.appendChild(document.createTextNode(child));
} else {
element.appendChild(child);
}
});
return element;
}
function generateTicket({
fromStation = 'Beijing',
toStation = 'SH',
trainNumber = '01-002',
date = '2024-04-05',
departureTime = '08:28',
color = 'green'
}) {
const colorMap = {
green: '#e8f6f6',
blue: '#e8f0f6',
pink: '#f6e8e8',
yellow: '#f6f3e8',
};
const id = Math.random().toString(36).substring(2, 10).toUpperCase() + 'Q';
const ticketDiv = createElement('div', {
class: 'ticket',
style: `background-color: ${colorMap[color]};`
});
// Ticket Number
const ticketNumberDiv = createElement('div', { class: 'ticket-number' }, id);
ticketDiv.appendChild(ticketNumberDiv);
// Stations
const stationsDiv = createElement('div', { class: 'station' },
createElement('span', null, `${fromStation} 站`),
createElement('span', { class: 'arrow' }, '→'),
createElement('span', null, `${toStation} 站`)
);
ticketDiv.appendChild(stationsDiv);
// Date and Train Info
const dateTrainDiv = createElement('div', { class: 'date-train' },
createElement('div', null, `${new Date(date).toLocaleDateString('zh-CN')} ${departureTime}开`),
createElement('div', null, `${trainNumber}号`)
);
ticketDiv.appendChild(dateTrainDiv);
// Additional Info
const additionalInfoDiv = createElement('div', { class: 'additional-info' },
createElement('div', null, '新至通特等座'),
createElement('div', null, '限乘当日当次车')
);
ticketDiv.appendChild(additionalInfoDiv);
// Bottom Section with QR Code
const bottomDiv = createElement('div', { class: 'bottom-section' });
const infoDiv = createElement('div', { class: 'info' },
createElement('div', { class: 'mb-1' },
createElement('span', null, '买票请到12306'),
createElement('span', null, '发货请到95306')
),
createElement('div', { class: 'insurance' }, '中国铁路旅客运输保险')
);
bottomDiv.appendChild(infoDiv);
// QR Code
const qrCodeDiv = createElement('img', {
src: `https://api.qrserver.com/v1/create-qr-code/?data=ticket:${id}&size=46x46`,
class: 'qr-code'
});
bottomDiv.appendChild(qrCodeDiv);
ticketDiv.appendChild(bottomDiv);
// Barcode placeholder
const barcodeDiv = createElement('div', { class: 'barcode' });
ticketDiv.appendChild(barcodeDiv);
return ticketDiv;
}
var ticket_card = generateTicket({
fromStation: '北京',
toStation: '上海',
trainNumber: 'G101',
date: '2024-05-01',
departureTime: '14:30',
color: 'pink'
})
_}``
<div>
``_ `<div>${ticket_card}</div>` _``
</div>
</div>
</div> block: |
Beta Was this translation helpful? Give feedback.
-
Hello, I've tried the showcase but the render command give me an error back. "Cannot read properties of undefined (reading 'content')" in line 40 of the jsx copy-pastet content. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Inspired by reddit post in
r/logseq
Let's replicate the book card from Logseq.com main page 💪
video
demo3.mp4
🏛view
for pages🏛view
(use copy button in the top right corner):code
name
,author
,category
and the link to book cover from the second page block (you could change it: see Tuning section).icon
property to[[Peter Morville]]
page:icon:: 👤
.🏛view
code to some block and enjoy book card:🏛view
for blocks🏛view
as for pages🏛view
for blocks:🏛view
code to some block and enjoy book card. Note: use:block
argument as content source for the view:Tuning the
🏛view
You could change the displaying content with
:cover
,:title
,:info1
,:info2
&:info3
arguments (or with its correspondingarg-
-prefixed properties in template block):@year
means🏛view
would accessyear
property of provided page or blockcover
argument and page source: if no property would be provided the value would be retrieved from the second page blockUse
:title-size
to change title's size. Available choices can be found here.{{renderer :template-view, book-card, :page [[Intertwingled]], :title-size text-xl}}
Use
:card-width
to change card's size (it is automatic by default):{{renderer :template-view, book-card, :page [[Intertwingled]], :card-width 350px}}
Use
:cover-height
&:cover-width
: to change card's cover size{{renderer :template-view, book-card, :page [[Intertwingled]], :cover-width 56px, :cover-height 84px}}
Additional info
Beta Was this translation helpful? Give feedback.
All reactions