Skip to content

Meta tag with image url content #618

Closed
@roadmanfong

Description

@roadmanfong

I 'd like to add something like

    <meta property="og:image" content="./src/images/cover.png" />
    <meta name="twitter:image" content="./src/images/cover.png" />

I notice that it didn't handle image inside the meta tag.
And I found a solution here
webpack-contrib/html-loader#17 (comment)

    <meta property="og:image" content="${require(`./src/images/cover.png`)}" />
    <meta name="twitter:image" content="${require(`./src/images/cover.png`)}" />

All we have to do is minor change in html loader setting
loader: 'html?interpolate=require',

roadmanfong@48bb6cf

Activity

added this to the 0.5.0 milestone on Sep 10, 2016
gaearon

gaearon commented on Sep 10, 2016

@gaearon
Contributor

Thanks for the suggestion.
I’m on the fence about the interpolate syntax but I’d like to keep this open and figure out a cohesive solution for this and related problems in a future release, so reopening.

kahneraja

kahneraja commented on Sep 17, 2016

@kahneraja

i'm super keen on resolving this. anyone got some tips or direction i can take here?

kahneraja

kahneraja commented on Sep 17, 2016

@kahneraja

I've noticed the following happens.

on build <link rel="shortcut icon" href="./src/favicon.ico"> becomes ><link rel="shortcut icon" href="/static/media/favicon.f9ba6907.ico">.

which is perfect. I want to extend that to other meta tags like <meta name="twitter:image:src" content="./src/title.jpg">

if anyone can point in the direction to PR that i'll do it :)

gaearon

gaearon commented on Sep 17, 2016

@gaearon
Contributor

The way I want it to work is that any attribute value starting with ./ should be processed via file-loader. But this needs to be implemented as a feature in html-loader and I’m not sure if they’re interested.

kahneraja

kahneraja commented on Sep 17, 2016

@kahneraja

How does <link rel="shortcut icon" href="./src/favicon.ico"> pick up required build change?

@gaearon - Is that something covered off in file-loader?

gaearon

gaearon commented on Sep 17, 2016

@gaearon
Contributor

No, it’s part of html-loader (usage).

We currently specify link:href as attrs option so that’s the only thing it picks up.
I want it to pick up any attribute value starting with ./: webpack-contrib/html-loader#17 (comment).

Relevant code is pretty small: https://github.com/webpack/html-loader/blob/master/index.js

kahneraja

kahneraja commented on Sep 17, 2016

@kahneraja

thanks @gaearon i'll look into it :)

kahneraja

kahneraja commented on Sep 17, 2016

@kahneraja

ah. i know understand we are looking at how this config gets picked up...
https://github.com/facebookincubator/create-react-app/blob/master/config/webpack.config.prod.js#L173

gaearon

gaearon commented on Sep 17, 2016

@gaearon
Contributor

Yep, that’s where it is.

kahneraja

kahneraja commented on Sep 17, 2016

@kahneraja

do we want to take a href-content place holder attribute approach?

<meta name="twitter:image:src" href-content="./src/title.jpg">
becomes
<meta name="twitter:image:src" content="http://wetrumphate.com/static/media/title.3c0fcf5e.jpg">

kahneraja

kahneraja commented on Sep 17, 2016

@kahneraja

hmm. i guess the idea of content starting with "./" is sort of better.

gaearon

gaearon commented on Sep 17, 2016

@gaearon
Contributor

I can’t really imagine why somebody would want to start their attributes with ./ and not mean a local file, so I think it will be safe to just assume that’s the intention.

11 remaining items

kahneraja

kahneraja commented on Sep 19, 2016

@kahneraja

@gaearon another thing.

from looking at this test it does sort of look like the html-loader guys are keen on sticking with the $(require('...')) approach.
https://github.com/webpack/html-loader/blob/master/test/loaderTest.js#L122

@zhuqiacheng? @sheerun?

kahneraja

kahneraja commented on Sep 19, 2016

@kahneraja

also... is there much of a difference between ${./src/img/title.jpg} and $require{./src/img/title.jpg}?

in my head they seem same-ish... ?

sheerun

sheerun commented on Sep 19, 2016

@sheerun
Contributor

As React shown, javascript is better than any templating language. Allowing ${} interpolation inside html allows not only with full webpack integration (like src="${require('../image.png')}", but also allows for seamless templating <div id="header">${require("../partials/header.html")}</div>. It's the easiest way to integrate with webpack dependency traversal.

For me allowing interpolation is both more powerful and actually easier to maintain in long run.

kahneraja

kahneraja commented on Sep 19, 2016

@kahneraja

If i understand things correctly, @gaearon i do tend to agree with @sheerun.

the standard interpolate approach is flexible and possibly easier to maintain.

If that's the case then fix to this would a PR to the 'create-react-app' to line up config and html files.

gaearon

gaearon commented on Sep 19, 2016

@gaearon
Contributor

OK, will accept a PR that adds interpolation syntax but disables automatic handling of link:href.

kahneraja

kahneraja commented on Sep 19, 2016

@kahneraja

on it :)

kahneraja

kahneraja commented on Sep 19, 2016

@kahneraja

getting a serious of failures when attempting to require interpolation with the dev config.
image
investigating....

gaearon

gaearon commented on Sep 19, 2016

@gaearon
Contributor

Maybe there’s some kind of typo in index.html?

gaearon

gaearon commented on Sep 22, 2016

@gaearon
Contributor

Meh, interpolation syntax is super annoying and hard to understand.
I’m working on another solution to this, stay tuned!

gaearon

gaearon commented on Sep 22, 2016

@gaearon
Contributor

I drafted a proposal to solve this in #703. Unless we find some fatal flaws, it should come out in 0.5.0. Let me know what you think!

gaearon

gaearon commented on Sep 22, 2016

@gaearon
Contributor

Closing as this is fixed, and will be released in 0.5.0.

gaearon

gaearon commented on Sep 23, 2016

@gaearon
Contributor

This is now supported in 0.5.0.

Read about using the new public folder.

See also migration instructions and breaking changes in 0.5.0.

locked and limited conversation to collaborators on Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sheerun@gaearon@roadmanfong@kahneraja

        Issue actions

          Meta tag with image url content · Issue #618 · facebook/create-react-app