tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
27
pulls
pipelines
fix links in interaction drawer preview
awarm.space
4 weeks ago
38d5a055
10133c25
+20
-32
4 changed files
expand all
collapse all
unified
split
app
(home-pages)
reader
InteractionDrawers.tsx
lish
createPub
getPublicationURL.ts
components
PostListing.tsx
src
useSelectedPostState.ts
+1
app/(home-pages)/reader/InteractionDrawers.tsx
···
60
60
const postUrl = getDocumentURL(
61
61
props.selectedPost.document,
62
62
props.selectedPost.document_uri,
63
63
+
props.selectedPost.publication,
63
64
);
64
65
65
66
const drawerTitle =
+11
-31
app/lish/createPub/getPublicationURL.ts
···
5
5
import {
6
6
normalizePublicationRecord,
7
7
isLeafletPublication,
8
8
-
hasLeafletContent,
9
8
type NormalizedDocument,
10
9
type NormalizedPublication,
11
10
} from "src/utils/normalizeRecords";
···
22
21
const normalized = normalizePublicationRecord(pub.record);
23
22
24
23
// If we have a normalized record with a URL (site.standard format), use it
25
25
-
if (normalized?.url && isProductionDomain()) {
24
24
+
if (normalized?.url) {
26
25
return normalized.url;
27
26
}
28
27
···
50
49
/**
51
50
* Gets the full URL for a document.
52
51
* Always appends the document's path property.
53
53
-
* For non-leaflet documents (content.$type !== "pub.leaflet.content"),
54
54
-
* always uses the full publication site URL, not internal /lish/ URLs.
55
52
*/
56
53
export function getDocumentURL(
57
54
doc: NormalizedDocument,
···
60
57
): string {
61
58
let path = doc.path || "/" + new AtUri(docUri).rkey;
62
59
if (path[0] !== "/") path = "/" + path;
63
63
-
const aturi = new AtUri(docUri);
64
60
65
65
-
const isNormalized =
66
66
-
!!publication &&
67
67
-
(publication as NormalizedPublication).$type ===
68
68
-
"site.standard.publication";
69
69
-
const normPub = isNormalized
70
70
-
? (publication as NormalizedPublication)
71
71
-
: publication
72
72
-
? normalizePublicationRecord((publication as PublicationInput).record)
73
73
-
: null;
74
74
-
const pubInput = isNormalized
75
75
-
? null
76
76
-
: (publication as PublicationInput | null);
77
77
-
78
78
-
// Non-leaflet documents always use the full publication site URL
79
79
-
if (doc.content && !hasLeafletContent(doc) && normPub?.url) {
80
80
-
return normPub.url + path;
61
61
+
if (!publication) {
62
62
+
return doc.site + path;
81
63
}
82
64
83
83
-
// For leaflet documents, use getPublicationURL (may return /lish/ internal paths)
84
84
-
if (pubInput) {
85
85
-
return getPublicationURL(pubInput) + path;
65
65
+
// Already-normalized publications: use URL directly
66
66
+
if (
67
67
+
(publication as NormalizedPublication).$type ===
68
68
+
"site.standard.publication"
69
69
+
) {
70
70
+
return ((publication as NormalizedPublication).url || doc.site) + path;
86
71
}
87
72
88
88
-
// When we only have a normalized publication, use its URL directly
89
89
-
if (normPub?.url) {
90
90
-
return normPub.url + path;
91
91
-
}
92
92
-
93
93
-
// Standalone document fallback
94
94
-
return `/p/${aturi.host}${path}`;
73
73
+
// Raw publication input: delegate to getPublicationURL for full resolution
74
74
+
return getPublicationURL(publication as PublicationInput) + path;
95
75
}
+3
components/PostListing.tsx
···
168
168
showMentions={mergedPrefs.showMentions !== false}
169
169
documentUri={props.documents.uri}
170
170
document={postRecord}
171
171
+
publication={pubRecord}
171
172
/>
172
173
<Share postUrl={postUrl} />
173
174
</div>
···
229
230
showMentions: boolean;
230
231
documentUri: string;
231
232
document: NormalizedDocument;
233
233
+
publication?: NormalizedPublication;
232
234
}) => {
233
235
let setSelectedPostListing = useSelectedPostListing(
234
236
(s) => s.setSelectedPostListing,
···
237
239
setSelectedPostListing({
238
240
document_uri: props.documentUri,
239
241
document: props.document,
242
242
+
publication: props.publication,
240
243
drawer,
241
244
});
242
245
};
+5
-1
src/useSelectedPostState.ts
···
1
1
import { create } from "zustand";
2
2
-
import type { NormalizedDocument } from "src/utils/normalizeRecords";
2
2
+
import type {
3
3
+
NormalizedDocument,
4
4
+
NormalizedPublication,
5
5
+
} from "src/utils/normalizeRecords";
3
6
4
7
export type SelectedPostListing = {
5
8
document_uri: string;
6
9
document: NormalizedDocument;
10
10
+
publication?: NormalizedPublication;
7
11
drawer: "quotes" | "comments";
8
12
};
9
13