-
Notifications
You must be signed in to change notification settings - Fork 334
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
Added support for preview links #2184 #2187
Open
seagulley
wants to merge
1
commit into
h2oai:main
Choose a base branch
from
seagulley:Support-for-preview-links-#2184
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+15
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -50,6 +50,9 @@ func newWebServer( | |||||
baseURL string, | ||||||
webDir string, | ||||||
header http.Header, | ||||||
previewImage string, | ||||||
previewTitle string, | ||||||
previewDescription string, | ||||||
) (*WebServer, error) { | ||||||
|
||||||
// read default index.html page from the web root | ||||||
|
@@ -58,15 +61,21 @@ func newWebServer( | |||||
return nil, fmt.Errorf("failed reading default index.html page: %v", err) | ||||||
} | ||||||
|
||||||
fs := handleStatic([]byte(mungeIndexPage(baseURL, string(indexPage))), http.StripPrefix(baseURL, http.FileServer(http.Dir(webDir))), header) | ||||||
fs := handleStatic([]byte(mungeIndexPage(baseURL, string(indexPage), previewImage, previewTitle, previewDescription)), http.StripPrefix(baseURL, http.FileServer(http.Dir(webDir))), header) | ||||||
if auth != nil { | ||||||
fs = auth.wrap(fs) | ||||||
} | ||||||
return &WebServer{site, broker, fs, keychain, maxRequestSize, baseURL}, nil | ||||||
} | ||||||
|
||||||
func mungeIndexPage(baseURL, html string) string { | ||||||
func mungeIndexPage(baseURL, html string, previewImage string, previewTitle string, previewDescription string) string { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Should be enough.
Suggested change
|
||||||
// HACK | ||||||
// add meta tags for preview image, title, description to the html string | ||||||
metaTags := fmt.Sprintf(`<meta property="og:image" content="%s"> | ||||||
<meta property="og:title" content="%s"> | ||||||
<meta property="og:description" content="%s">`, previewImage, previewTitle, previewDescription) | ||||||
mturoci marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
html = strings.Replace(html, "<head>", "<head>"+metaTags, 1) | ||||||
|
||||||
// set base URL as a body tag attribute, to be used by the front-end for deducing hash-routing and websocket addresses. | ||||||
html = strings.Replace(html, "<body", `<body data-base-url="`+baseURL+`"`, 1) | ||||||
// ./wave-static/a/b/c.d -> /base-url/wave-static/a/b/c.d | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make these part of the https://github.com/h2oai/wave/blob/94bf37f538719ad279a41b0df1b452623d61aaa4/conf.go#L71C7-L71C7 as well to expose new options to the users.
Also document here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll get started on this as well as a demo :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Martin,
I started working on the demo. Using Meta's Open Graph debugger, it can read the custom title and description, but there are some issues with the image.
I did some more digging and there are some guidelines for adding images to preview links
https://developers.facebook.com/docs/sharing/best-practices/#precaching
How should I approach this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning says all it needs are
og:image:height
andog:image:width
props. I would first try it out to see if they help. If they do, the next step would be to validate passed image dimensions and:Hope that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that makes sense I'll get started on it!