{"id":13582693,"url":"https://github.com/ghorsey/OpenGraph-Net","last_synced_at":"2025-04-06T14:31:12.805Z","repository":{"id":1335113,"uuid":"1280936","full_name":"ghorsey/OpenGraph-Net","owner":"ghorsey","description":".Net Open Graph Parser written in C#","archived":false,"fork":false,"pushed_at":"2025-01-14T22:08:32.000Z","size":2706,"stargazers_count":130,"open_issues_count":6,"forks_count":35,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-03-30T05:02:33.196Z","etag":null,"topics":["c-sharp","nuget","ogp","opengraph","opengraph-net","parse"],"latest_commit_sha":null,"homepage":"https://ghorsey.github.io/OpenGraph-Net/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghorsey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-01-22T03:20:16.000Z","updated_at":"2025-03-12T23:32:11.000Z","dependencies_parsed_at":"2024-11-05T22:33:49.138Z","dependency_job_id":null,"html_url":"https://github.com/ghorsey/OpenGraph-Net","commit_stats":{"total_commits":274,"total_committers":5,"mean_commits":54.8,"dds":"0.27007299270072993","last_synced_commit":"0be59e13dc7b9461289d7d8b9d8920478cfd6fcd"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghorsey%2FOpenGraph-Net","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghorsey%2FOpenGraph-Net/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghorsey%2FOpenGraph-Net/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghorsey%2FOpenGraph-Net/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghorsey","download_url":"https://codeload.github.com/ghorsey/OpenGraph-Net/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441042,"owners_count":20939239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","nuget","ogp","opengraph","opengraph-net","parse"],"created_at":"2024-08-01T15:02:56.752Z","updated_at":"2025-04-06T14:31:12.800Z","avatar_url":"https://github.com/ghorsey.png","language":"HTML","funding_links":["https://www.buymeacoffee.com/ghorsey)!"],"categories":["HTML"],"sub_categories":[],"readme":"# OpenGraphNet\n\n[![Build](https://github.com/ghorsey/OpenGraph-Net/actions/workflows/main.yml/badge.svg)](https://github.com/ghorsey/OpenGraph-Net/actions/workflows/main.yml)\n[![Nuget V](https://img.shields.io/nuget/v/OpenGraph-Net.svg)](http://www.nuget.org/packages/OpenGraph-Net/)\n[![Nuget dl](https://img.shields.io/nuget/dt/OpenGraph-Net.svg)](http://www.nuget.org/packages/OpenGraph-Net/)\n[![License](https://img.shields.io/badge/license-MIT-orange.svg)](https://github.com/ghorsey/OpenGraph-Net/blob/main/LICENSE)\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/ghorsey/OpenGraph-Net/blob/main/CODE_OF_CONDUCT.md)\n[![gitter](https://badges.gitter.im/webpack/webpack.svg)](https://gitter.im/OpenGraph-Net/OpenGraph-Net)\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=round-square)](#contributors-)\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n[![Open in DevPod!](https://devpod.sh/assets/open-in-devpod.svg)](https://devpod.sh/open#https://github.com/ghorsey/OpenGraph-Net)\n\nA simple .net assembly to use to parse Open Graph information from either a URL or an HTML snippet. You can read more about the\nOpen Graph protocol @ \u003chttp://ogp.me\u003e.\n\n## Support the library\n\nIf you find this library useful, [buy me a coffee](https://www.buymeacoffee.com/ghorsey)!\n\n## Usage\n\nThese are the basic operations of the OpenGraphNet parser.\n\n### Parsing from a URL\n\nUse `async/await` to parse a URL:\n\n```csharp\nOpenGraph graph = await OpenGraph.ParseUrlAsync(\"https://open.spotify.com/user/er811nzvdw2cy2qgkrlei9sqe/playlist/2lzTTRqhYS6AkHPIvdX9u3?si=KcZxfwiIR7OBPCzj20utaQ\");\n```\n\n### Accessing Values\n\n#### Accessing Metadata\n\nEach metadata element is stored as an array. Additionally, each element's properties are also stored as an array.\n\n```html\n\u003cmeta property=\"og:image\" content=\"http://example.com/img1.png\"\u003e\n\u003cmeta property=\"og:image:width\" content=\"30\"\u003e\n\u003cmeta property=\"og:image\" content=\"http://example.com/img2.png\"\u003e\n\u003cmeta property=\"og:image:width\" content=\"60\"\u003e\n\u003cmeta property=\"og:locale\" content=\"en\"\u003e\n\u003cmeta property=\"og:locale:alternate\" content=\"en_US\"\u003e\n\u003cmeta property=\"og:locale:alternate\" content=\"en_GB\"\u003e\n```\n\nYou would access the values from the sample HTML above as:\n\n```csharp\ngraph.Metadata[\"og:image\"].First().Value; // \"http://example.com/img1.png\"\ngraph.Metadata[\"og:image\"].First().Properties[\"width\"].Value(); // \"30\"\ngraph.Metadata[\"og:image\"][1].Value; // \"http://example.com/img2.png\"\ngraph.Metadata[\"og:image\"][1].Properties[\"width\"].Value(); // \"30\"\ngraph.Metadata[\"og:locale\"].Value(); // \"en\"\ngraph.Metadata[\"og:locale\"].First().Properties[\"alternate\"][0].Value; // \"en_US\"\ngraph.Metadata[\"og:locale\"].First().Properties[\"alternate\"][1].Value; // \"en_GB\"\n```\n\n#### Basic Metadata\n\nThe four required Open Graph properties for all pages are available as direct properties on the OpenGraph object.\n\n* `graph.Type` is a shortcut for `graph.Metadata[\"og:type\"].Value()`\n* `graph.Title` is a shortcut for `graph.Metadata[\"og:title\"].Value()`\n* `graph.Image` is a shortcut for `graph.Metadata[\"og:image\"].Value()`\n* Note: since there can be multiple images, this helper returns the URI of the\nfirst image.  If you want to access images or child properties like `og:image:width` then you\nshould instead use the `graph.Metadata` dictionary.*\n* `graph.Url` is a shortcut for `graph.Metadata[\"og:url\"].Value()`\n\n#### Misc\n\nThe original URL used to generate the OpenGraph data is available from the `OriginalUrl` property\n`graph.OriginalUrl`.\n\n### Creating OpenGraph Data\n\nTo create OpenGraph data in memory use the following code:\n\n```csharp\nvar graph = OpenGraph.MakeGraph(\n    title: \"My Title\", \n    type: \"website\", \n    image: \"http://example.com/img/img1.png\", \n    url: \"http://example.com/home\", \n    description: \"My Description\", \n    siteName: \"Example.com\");\ngraph.AddMetadata(\"og\", \"image\", \"http://example.com/img/img2.png\");\ngraph.Metadata[\"og:image\"][0].AddProperty(\"width\", \"30\");\ngraph.Metadata[\"og:image\"][1].AddProperty(\"width\", \"60\");\nSystem.Console.Write(graph.ToString());\n```\n\nThe previous `System.Console.Write(graph.ToString());` will produce the following HTML (formatting added for legibility):\n\n```html\n\u003cmeta property=\"og:title\" content=\"My Title\"\u003e\n\u003cmeta property=\"og:type\" content=\"website\"\u003e\n\u003cmeta property=\"og:image\" content=\"http://example.com/img/img1.png\"\u003e\n\u003cmeta property=\"og:image:width\" content=\"30\"\u003e\n\u003cmeta property=\"og:image\" content=\"http://example.com/img/img2.png\"\u003e\n\u003cmeta property=\"og:image:width\" content=\"60\"\u003e\n\u003cmeta property=\"og:url\" content=\"http://example.com/home\"\u003e\n\u003cmeta property=\"og:description\" content=\"My Description\"\u003e\n\u003cmeta property=\"og:site_name\" content=\"Example.com\"\u003e\n```\n\n### Parsing Namespaces\n\nThe component now knows about the 13 namespaces listed below.  When parsing a url or a HTML\ndocument, OpenGraph.Net will now read and use those namespaces from either the `\u003chtml\u003e` or\n`\u003chead\u003e` tags.  The parser is now smart enough to include the namespaces when none are\nincluded in those tags by extracting it from the `meta[property]` value directly.\n\n* og: \u003chttp://ogp.me/ns#\u003e\n  * Expected fields when validating: `title`, `type`, `image`, `url`\n* article: \u003chttp://ogp.me/ns/article#\u003e\n* book: \u003chttp://ogp.me/ns/book#\u003e\n* books: \u003chttp://ogp.me/ns/books#\u003e\n* business \u003chttp://ogp.me/ns/business#\u003e\n* fitness: \u003chttp://ogp.me/ns/fitness#\u003e\n* game: \u003chttp://ogp.me/ns/game#\u003e\n* music: \u003chttp://ogp.me/ns/music#\u003e\n* place: \u003chttp://ogp.me/ns/place#\u003e\n* product: \u003chttp://ogp.me/ns/product#\u003e\n* profile: \u003chttp://ogp.me/ns/profile#\u003e\n* restaurant: \u003chttp://ogp.me/ns/restaurant#\u003e\n* video: \u003chttp://ogp.me/ns/video#\"\u003e\n\n*If there are any additional standard/supported namespaces that I am missing, please shoot me\na comment or a pull request with the missing items.*\n\n#### Adding Custom Namespaces\n\nYou can now add custom namespaces to the parser.  Simply make the following call:\n\n```csharp\nNamespaceRegistry.Instance.AddNamespace(\n    prefix: \"gah\",\n    schemaUri: \"http://wwww.geoffhorsey.com/ogp/brain#\",\n    requiredElements: new[] { \"brain\" });\n```\n\nDoing the above will allow the parser to understand the following HTML snippet:\n\n```html\n\u003cmeta property=\"gah:brain\" content=\"http://www.geoffhorsey.com/my-brain\"\u003e\n\u003cmeta property=\"gah:brain:size\" content=\"tiny\"\u003e\n```\n\nand the graph:\n\n```csharp\ngraph.Metadata[\"gah:brain\"].Value() // \"http://www.geoffhorsey.com/my-brain\"\ngraph.Metadata[\"gah:brain\"].First().Properties[\"size\"].Value() // \"tiny\"\n```\n\n### Writing out OpenGraph Namespaces\n\nIn the wild web sites seem to add their OpenGraph namespaces in one of 2 ways.  They either\nwrite the namespaces in the `html` as `xmlns` attributes or within the `head` tag in the `prefix` attribute.\n\n* `\u003chtml xmlns:og=\"http://ogp.me/ns#\" xmlns:product=\"http://ogp.me/ns/product#\"\u003e`\n* `\u003chead prefix=\"og: http://ogp.me/ns# product: http://ogp.me/ns/product#\"\u003e`\n\n**`xmlns:` version in the `html` tag**\n\nTo create the `html` version in an cshtml page after creating a new `graph`, use the following code:\n\n```html\n\u003chtml @graph.HtmlXmlnsValues\u003e\n```\n\nWould produce the following:\n\n```html\n\u003chtml xmlns:og=\"http://ogp.me/ns#\" xmlns:product=\"http://ogp.me/ns/product#\"\u003e\n```\n\n#### `prefix` version in the `\u003chead\u003e` tag\n\nTo create the `head` version in a cshtml page, after create a new `graph`, use the following code:\n\n```html\n\u003chead prefix=\"@graph.HeadPrefixAttributeValue\"\u003e\n```\n\nWould produce the following:\n\n```html\n\u003chead prefix=\"og: http://ogp.me/ns# product: http://ogp.me/ns/product#\"\u003e\n```\n\n### Writing out OpenGraph Metadata to the `head` tag\n\nBelow is a complete example to write out a OpenGraph metadata to a page:\n\n```html\n@{\n    var graph = OpenGraph.MakeGraph(\n        title: \"My Title\", \n        type: \"website\", \n        image: \"http://example.com/img/img1.png\", \n        url: \"http://example.com/home\", \n        description: \"My Description\", \n        siteName: \"Example.com\");\n}\n\u003chtml\u003e\n\u003chead prefix=\"@graph.HeadPrefixAttributeValue\"\u003e\n    @graph.ToString()\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003c!-- Your awesome page! --\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nwill produce the following HTML:\n\n```html\n\u003chtml\u003e\n\u003chead prefix=\"og: http://ogp.me/ns#\"\u003e\n    \u003cmeta property=\"og:title\" content=\"My Title\"\u003e\n    \u003cmeta property=\"og:type\" content=\"website\"\u003e\n    \u003cmeta property=\"og:image\" content=\"http://example.com/img/img1.png\"\u003e\n    \u003cmeta property=\"og:url\" content=\"http://example.com/home\"\u003e\n    \u003cmeta property=\"og:description\" content=\"My Description\"\u003e\n    \u003cmeta property=\"og:site_name\" content=\"Example.com\"\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003c!-- Your awesome page! --\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## It's FOSS\n\nSo please don't be afraid to [fork me](https://github.com/ghorsey/OpenGraph-Net).\n\n### Contribution Guide\n\n1. Fork the OpenGraph-Net repository\n2. Create a feature branch for the item you are going to add.\n3. Add your awesome code and your unit tests to cover the new feature\n4. Run all of the tests to ensure everything is still passing.\n5. Create a pull request to our `develop` branch.\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://www.geoffhorsey.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/448706?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eGeoff\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/ghorsey/OpenGraph-Net/commits?author=ghorsey\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/ghorsey/OpenGraph-Net/commits?author=ghorsey\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#ideas-ghorsey\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"#platform-ghorsey\" title=\"Packaging/porting to new platform\"\u003e📦\u003c/a\u003e \u003ca href=\"#projectManagement-ghorsey\" title=\"Project Management\"\u003e📆\u003c/a\u003e \u003ca href=\"https://github.com/ghorsey/OpenGraph-Net/commits?author=ghorsey\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://osbeck.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/982752?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ePer Osbäck\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/ghorsey/OpenGraph-Net/commits?author=perosb\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghorsey%2FOpenGraph-Net","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghorsey%2FOpenGraph-Net","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghorsey%2FOpenGraph-Net/lists"}