Skip to content

Meta tag with image url content #618

Closed

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/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

  1. added this to the 0.5.0 milestone on Sep 10, 2016
  2. 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.

  3. kahneraja commented on Sep 17, 2016

    @kahneraja

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

  4. 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 :)

  5. 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.

  6. 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?

  7. 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/html-loader#17 (comment).

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

  8. kahneraja commented on Sep 17, 2016

    @kahneraja

    thanks @gaearon i'll look into it :)

  9. 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

  10. gaearon commented on Sep 17, 2016

    @gaearon
    Contributor

    Yep, that’s where it is.

  11. 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">

  12. kahneraja commented on Sep 17, 2016

    @kahneraja

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

  13. 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.

  14. 10 remaining items

  15. kahneraja commented on Sep 19, 2016

    @kahneraja

    @gaearon can i just confirm you mean to add 2 separate PRs.

    one to make html-loader pick up on any meta tag with content like this?

    <meta name="twitter:image:src" content="${`./src/img/title.jpg`}">
    

    and one to remove that config settings from create-react-app?

    ... attrs: ['link:href'], // remove
    
  16. 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?

  17. 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... ?

  18. 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.

  19. 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.

  20. gaearon commented on Sep 19, 2016

    @gaearon
    Contributor

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

  21. kahneraja commented on Sep 19, 2016

    @kahneraja

    on it :)

  22. kahneraja commented on Sep 19, 2016

    @kahneraja

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

  23. gaearon commented on Sep 19, 2016

    @gaearon
    Contributor

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

  24. 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!

  25. 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!

  26. gaearon commented on Sep 22, 2016

    @gaearon
    Contributor

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

  27. 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.

  28. 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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions