From a48def1358de7d19d68d85348bd84e2f3d0f9d31 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 3 Feb 2020 01:30:17 +0530 Subject: [PATCH 1/3] Initial commit Signed-off-by: Harsh Shandilya --- LICENSE | 20 ++++++++++++++++++++ README.md | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ad44906 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2020 Harsh Shandilya + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5a55869 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# hugo-social-metadata + +## About + +This is a [Hugo](https://gohugo.io) theme component that automatically generates metadata complying to [The Open Graph Protocol](https://ogp.me/) as well as [Twitter Cards](https://developer.twitter.com/en/docs/tweets/optimize-with-cards/guides/getting-started). This is **NOT** a standalone theme and must not be treated as such. + +## Usage + +1. Add the hugo-social-metadata repository as a submodule to be able to get upstream changes later `git submodule add https://github.com/msfjarvis/hugo-social-metadata.git themes/hugo-social-metadata` + +2. Start off by configuring a few things in your `config.toml` (or equivalent file depending on whether you use YAML or JSON). These will be picked up by the theme component and used to provide metadata for the site. + +```toml +[params] + description = "A description for your awesome website goes here" + keywords = "some, keywords, that, describe, your, content" + twitterUsername = "@your_twitter_username" + socialImage = "path/to/the/twitter/card/image" +``` + +3. Include the `social_metadata.html` partial in your `head.html` like so: `{{ partial "social_metadata.html" . }}`. + +## Additional customizations + +You can customize some of the generated metadata on a per-page basis. Setting `description`, `socialImage` or `tags` in the frontmatter will override the defaults loaded from the main config file. + +```markdown ++++ +description = "A nice description for this blogpost" +socialImage = "path/to/an/image/that/describes/this/post/best" +tags = ["this", "blog", "rocks!"] ++++ +``` + +## License + +Check out the [LICENSE](/LICENSE) file in the root of this repository. From 2e80cc3f4ae039f12796652abbc377a77fe99c0e Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 3 Feb 2020 01:36:22 +0530 Subject: [PATCH 2/3] Code drop Signed-off-by: Harsh Shandilya --- layouts/partials/social_metadata.html | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 layouts/partials/social_metadata.html diff --git a/layouts/partials/social_metadata.html b/layouts/partials/social_metadata.html new file mode 100644 index 0000000..cfb0060 --- /dev/null +++ b/layouts/partials/social_metadata.html @@ -0,0 +1,41 @@ + + + + +{{ if .IsHome }} +{{ .Site.Title }} + + + + + + + + + + +{{ else }} +{{ .Title }} · {{ .Site.Title }} + +{{ if .Params.tags }} + +{{ else }} + +{{ end }} + + + +{{ if .Description }} + + +{{ else }} + + +{{ end }} + +{{ if .Params.SocialImage }} + +{{ else }} + +{{ end }} +{{ end }} From da03beb04de194680747f7cc6cdb94cb02f7c64f Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 3 Feb 2020 01:39:16 +0530 Subject: [PATCH 3/3] Don't hardcode Twitter username Signed-off-by: Harsh Shandilya --- layouts/partials/social_metadata.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/layouts/partials/social_metadata.html b/layouts/partials/social_metadata.html index cfb0060..7a5b9fb 100644 --- a/layouts/partials/social_metadata.html +++ b/layouts/partials/social_metadata.html @@ -1,7 +1,9 @@ - +{{ if .Site.Params.TwitterUsername }} + +{{ end }} {{ if .IsHome }} {{ .Site.Title }}