Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] v4 from jackyzha0:v4 #21

Merged
merged 7 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/features/callouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ See [documentation on supported types and syntax here](https://help.obsidian.md

> [!question]+ Can callouts be nested?
>
> > [!todo]- Yes!, they can.
> > [!todo]- Yes!, they can. And collapsed!
> >
> > > [!example] You can even use multiple layers of nesting.

Expand Down
18 changes: 18 additions & 0 deletions quartz/components/scripts/spa.inline.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import micromorph from "micromorph"
import { FullSlug, RelativeURL, getFullSlug } from "../../util/path"
import { normalizeRelativeURLs } from "./popover.inline"

// adapted from `micromorph`
// https://github.com/natemoo-re/micromorph
Expand All @@ -18,6 +19,12 @@ const isLocalUrl = (href: string) => {
return false
}

const isSamePage = (url: URL): boolean => {
const sameOrigin = url.origin === window.location.origin
const samePath = url.pathname === window.location.pathname
return sameOrigin && samePath
}

const getOpts = ({ target }: Event): { url: URL; scroll?: boolean } | undefined => {
if (!isElement(target)) return
if (target.attributes.getNamedItem("target")?.value === "_blank") return
Expand Down Expand Up @@ -46,6 +53,8 @@ async function navigate(url: URL, isBack: boolean = false) {
if (!contents) return

const html = p.parseFromString(contents, "text/html")
normalizeRelativeURLs(html, url)

let title = html.querySelector("title")?.textContent
if (title) {
document.title = title
Expand Down Expand Up @@ -93,8 +102,16 @@ function createRouter() {
if (typeof window !== "undefined") {
window.addEventListener("click", async (event) => {
const { url } = getOpts(event) ?? {}
// dont hijack behaviour, just let browser act normally
if (!url || event.ctrlKey || event.metaKey) return
event.preventDefault()

if (isSamePage(url) && url.hash) {
const el = document.getElementById(decodeURIComponent(url.hash.substring(1)))
el?.scrollIntoView()
return
}

try {
navigate(url, false)
} catch (e) {
Expand Down Expand Up @@ -140,6 +157,7 @@ if (!customElements.get("route-announcer")) {
style:
"position: absolute; left: 0; top: 0; clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap; width: 1px; height: 1px",
}

customElements.define(
"route-announcer",
class RouteAnnouncer extends HTMLElement {
Expand Down
9 changes: 7 additions & 2 deletions quartz/plugins/emitters/aliases.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FilePath, FullSlug, resolveRelative, simplifySlug } from "../../util/path"
import { FilePath, FullSlug, joinSegments, resolveRelative, simplifySlug } from "../../util/path"
import { QuartzEmitterPlugin } from "../types"
import path from "path"

Expand All @@ -25,7 +25,12 @@ export const AliasRedirects: QuartzEmitterPlugin = () => ({
slugs.push(permalink as FullSlug)
}

for (const slug of slugs) {
for (let slug of slugs) {
// fix any slugs that have trailing slash
if (slug.endsWith("/")) {
slug = joinSegments(slug, "index") as FullSlug
}

const redirUrl = resolveRelative(slug, file.data.slug!)
const fp = await emit({
content: `
Expand Down
2 changes: 2 additions & 0 deletions quartz/plugins/emitters/contentIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FilePath, FullSlug, SimpleSlug, simplifySlug } from "../../util/path"
import { QuartzEmitterPlugin } from "../types"
import { toHtml } from "hast-util-to-html"
import path from "path"
import { byDateAndAlphabetical } from "../../components/PageList"

export type ContentIndex = Map<FullSlug, ContentDetails>
export type ContentDetails = {
Expand Down Expand Up @@ -59,6 +60,7 @@ function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: nu
</item>`

const items = Array.from(idx)
.sort((a, b) => byDateAndAlphabetical(cfg)(a[1], b[1]))
.map(([slug, content]) => createURLEntry(simplifySlug(slug), content))
.slice(0, limit ?? idx.size)
.join("")
Expand Down
26 changes: 18 additions & 8 deletions quartz/styles/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -390,23 +390,33 @@ p {
line-height: 1.6rem;
}

table {
margin: 1rem;
padding: 1.5rem;
border-collapse: collapse;
& > * {
line-height: 2rem;
.table-container {
overflow-x: auto;

& > table {
margin: 1rem;
padding: 1.5rem;
border-collapse: collapse;

th,
td {
min-width: 75px;
}

& > * {
line-height: 2rem;
}
}
}

th {
text-align: left;
padding: 0.4rem 1rem;
padding: 0.4rem 0.7rem;
border-bottom: 2px solid var(--gray);
}

td {
padding: 0.2rem 1rem;
padding: 0.2rem 0.7rem;
}

tr {
Expand Down
15 changes: 0 additions & 15 deletions quartz/util/jsx.ts

This file was deleted.

28 changes: 28 additions & 0 deletions quartz/util/jsx.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Components, Jsx, toJsxRuntime } from "hast-util-to-jsx-runtime"
import { QuartzPluginData } from "../plugins/vfile"
import { Node, Root } from "hast"
import { Fragment, jsx, jsxs } from "preact/jsx-runtime"
import { trace } from "./trace"
import { type FilePath } from "./path"

const customComponents: Components = {
table: (props) => (
<div class="table-container">
<table {...props} />
</div>
),
}

export function htmlToJsx(fp: FilePath, tree: Node<QuartzPluginData>) {
try {
return toJsxRuntime(tree as Root, {
Fragment,
jsx: jsx as Jsx,
jsxs: jsxs as Jsx,
elementAttributeNameCase: "html",
components: customComponents,
})
} catch (e) {
trace(`Failed to parse Markdown in \`${fp}\` into JSX`, e as Error)
}
}