Comments (5)
Yes absolutely! The current setup is meant to be a building block for creating an abstract metadata structure that later can be translated into HTML/json+ld and maybe even other things.
I've mostly built the tool around my own needs and haven't really had the time to dig deep and do an analysis on the HTML spec to build something that fits all use cases
Which kinds of links do you envision metatags to take care of (other than the canonical example)?
from metatags.
Hi Johan and thanks for your quick response!
I tried to get the following (additional) meta/link tags in the page head:
<link rel="next" href="https://mydomain/article?page=2" />
<link rel="alternate" hreflang="de-de" href="https://mydomain.de/article">
<link rel="alternate" hreflang="de-ch" href="https://mydomain.ch/article">
<link rel="apple-touch-icon-precomposed" href="https://mydomain/icon.png">
<link rel="apple-touch-icon-precomposed" href="https://mydomain/icon144.png" sizes="144x144">
Thanks in advance
from metatags.
Ok, so I've thought a bit about this and some of them are quite easy to add, such as adding the next
. That would be as simple as adding a clause that know how the "next"
key means it should be a link.
We're however limited to using a key/value approach right now which makes it impossible to create things like alternate
, which would also require a hreflang
to be set.
What do you think of an approach like this:
Add Metatags.put/4
where the fourth parameter can include whatever the extra attributes can be. Typical usage would look like this:
Metatags.put(@conn, "alternate", "https://mydomain.de/article", hreflang: "de-de")
What do you think? Does it feel reasonable?
from metatags.
Hi and sorry for my late response!
I thought a lot about your question and have chosen another approach:
-
I have a db-table of page-urls where the meta-config is stored and can be edited (but it could be a static config-file either)
-
I have a Plug that takes the request-url, fetches the meta-config and puts the following map into the assigns:
metatags = %{
link: [
%{rel: "canonical", href: canonical},
%{rel: "alternate", hreflang: "de-de", href: "https://mydomain.de#{path}"},
%{rel: "alternate", hreflang: "de-ch", href: "https://mydomain.ch#{path}"}
],
meta: [{:robots, robots}, {:title, title}, {:description, description}]
}
conn |> assign(:metatags, metatags)
I think this structure is very flexible - you can put there whatever you need.
3.) In the layout.html I have just one call in the section
<%= raw metatags(assigns) %>
4.) And to put it all together this is the layout_view (this is where the magic happens):
def metatags(assigns) do
assigns
|> Map.get(:metatags)
|> render_metatags()
end
defp render_metatags(%{link: link, meta: meta}) do
[Enum.map(meta, &meta_tag/1), Enum.map(link, &link_tag/1)]
|> Enum.join("")
|> (&"#{&1}\n").()
end
defp render_metatags(_), do: ""
defp link_tag(link) do
link
|> Map.to_list()
|> Enum.map(fn {key, value} -> ~s(#{key}="#{value}") end)
|> List.insert_at(0, "<link")
|> List.insert_at(-1, "/>")
|> Enum.join(" ")
end
defp meta_tag({:title, content}), do: ~s(<title>#{content}</title>)
defp meta_tag({name, content}), do: ~s(<meta name="#{name}" content="#{content}" />)
So what do you think? I don't say it's the best solution, but maybe useful.
from metatags.
While that would be generic enough to cover all cases it would make it harder to generalize the information.
My long term plan is to find a data structure that can be passed to different printers, such as Metatags.Printers.HTML
and Metatags.Printers.JSONLD
to enable the information to be used in multiple ways. If we were to bind it too tightly to how it will be printed in HTML that wouldn't be possible.
I merged #16 which would solve your problem and will work towards the goal above. The only problem I'm currently having is that I don't have many projects with strong SEO needs that I can use as need to fill. You seem to have more needs that I do at this point so maybe you can continue to open up issues for things that limit you? That would be appreciated!
from metatags.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metatags.