# Sitepress

## Getting Started

## Create a connection

1. Sign in to [OpenGraph+](/)
2. Go to your website's **Meta Tags** page
3. Create a new connection and copy your connection URL

Your connection URL looks like `https://$OGPLUS_KEY.ogplus.net`.

## Find your layout

Sitepress layouts live in `app/views/layouts/` alongside your Rails layouts. If your site uses a shared layout like `application.html.erb`, that's where you'll add Open Graph meta tags so every page inherits them.

## Add Open Graph meta tags

Add the following meta tags to your layout's `<head>`. These control how your pages appear when shared on Twitter, Slack, LinkedIn, and other platforms.

```erb
<!-- app/views/layouts/application.html.erb -->
<html>
  <head>
    <meta property="og:title" content="<%= current_page.data.title || "My Site" %>">
    <meta property="og:description" content="<%= current_page.data.description || "Welcome to my site" %>">
    <meta property="og:url" content="<%= request.original_url %>">
    <meta property="og:site_name" content="My Site">
    <meta property="og:type" content="website">
    <meta property="og:image" content="https://$OGPLUS_KEY.ogplus.net<%= current_page.request_path %>">
    <meta name="twitter:card" content="summary_large_image">
  </head>
  <body>
    <%= yield %>
  </body>
</html>
```

Replace `https://$OGPLUS_KEY.ogplus.net` with your connection URL, and `"My Site"` with your actual site name.

### What each tag does

| Tag | Purpose |
|-----|---------|
| `og:title` | The title shown in the link preview |
| `og:description` | The description shown below the title |
| `og:url` | The canonical URL of the page |
| `og:site_name` | Your website's name |
| `og:type` | Content type (`website`, `article`, `product`) |
| `og:image` | The social card image (powered by OpenGraph+) |
| `twitter:card` | Tells Twitter to show a large image card |

## Set dynamic tags from frontmatter

Sitepress pages define their metadata via YAML frontmatter. The layout picks up these values automatically through `current_page.data`:

```markdown
---
title: How to Build a Site with Sitepress
description: A step-by-step guide to building a fast content site.
---

Your page content here.
```

You can also set tags from a Sitepress layout so they apply to every page that uses it:

```erb
<%# app/content/layouts/blog.html.erb %>
<% content_for(:og_type) { "article" } %>
<%= yield %>
```

Then use `content_for` in the application layout to pick it up:

```erb
<meta property="og:type" content="<%= content_for(:og_type) || "website" %>">
```

## Verify

Start your development server and view the page source. Check that all `og:` meta tags are present with the correct values.

Open the preview tool in your OpenGraph+ dashboard and paste a URL from your site to see the social card image.


## Customize

Sitepress runs on Rails, so all customization options from the [Rails customize guide](/docs/rails/customize) apply directly. This page shows the same techniques with Sitepress-specific file paths.

## Meta tags

Add these to your layout's `<head>` alongside your `og:image` tag. They're all optional.

```erb
<head>
  <meta property="og:image" content="https://$OGPLUS_KEY.ogplus.net<%= current_page.request_path %>">
  <meta name="twitter:card" content="summary_large_image">

  <%# Render at 800px wide instead of the default %>
  <meta property="og:plus:viewport:width" content="800">

  <%# Only capture this element instead of the full page %>
  <meta property="og:plus:selector" content=".page-header">

  <%# Inject inline styles on the captured element %>
  <meta property="og:plus:style" content="padding: 60px; background: #0f172a; color: white;">
</head>
```

See the [Rendering](/docs/html-css/rendering) guide for what each meta tag does and how they interact.

## CSS styling

OpenGraph+ adds a `data-ogplus` attribute to your `<html>` element during capture. Use it in your stylesheets to hide navigation, adjust spacing, or restyle anything for the social card without affecting your actual site.

```css
/* app/assets/stylesheets/application.css */
html[data-ogplus] {
  nav { display: none; }
  footer { display: none; }
  .hero { padding: 60px; }
}
```

If you're using Tailwind, there's a plugin that gives you `ogplus:` variants like `ogplus:hidden` and `ogplus-twitter:bg-sky-500`. See [CSS Styling](/docs/html-css/data-attributes) for plain CSS examples and [Tailwind setup](/docs/html-css/data-attributes#tailwind-css).

## Templates

For fully custom social card layouts that pull content from your page, use `<template>` elements.

```erb
<%# app/views/layouts/application.html.erb %>
<template id="ogplus">
  <div style="padding: 48px; background: #0f172a; color: white; height: 100%;">
    <h1 style="font-size: 48px;">
      ${document.querySelector('h1')?.textContent}
    </h1>
  </div>
</template>
```

See the [Templates](/docs/html-css/templates) guide for expression syntax, platform-specific templates, and full examples.

## Testing locally

The [Preview Bookmarklet](/docs/html-css/bookmarklet) sets the `data-ogplus` attribute in your browser so you can see how your CSS and Tailwind variants look without deploying or waiting for a real crawler to hit your page.

## Full example

A layout with all the pieces together:

```erb
<head>
  <meta property="og:title" content="<%= current_page.data.title || "My Site" %>">
  <meta property="og:description" content="<%= current_page.data.description || "Welcome" %>">
  <meta property="og:image" content="https://$OGPLUS_KEY.ogplus.net<%= current_page.request_path %>">
  <meta name="twitter:card" content="summary_large_image">
  <meta property="og:plus:selector" content=".page-header">
  <meta property="og:plus:style" content="padding: 60px; background-color: #0f172a; color: white;">
  <meta property="og:plus:viewport:width" content="800">
</head>
```


## Caching

Sitepress runs on Rails, so all caching techniques from the [Rails caching guide](/docs/rails/caching) apply directly. Use `expires_in` and `fresh_when` in your controllers to set HTTP cache headers.

This page covers the Sitepress side. For how OpenGraph+ handles caching at the HTTP level, see the [HTTP Caching](/docs/html-css/caching) guide.

## Meta tag overrides

If your pages are served statically or you want per-page cache control without a controller, add meta tags to your layout:

```erb
<meta property="og:plus:cache:max_age" content="86400">
<meta property="og:plus:cache:etag" content="<%= current_page.data.version || 'v1' %>">
```

Use frontmatter to set per-page cache versions:

```markdown
---
title: My Page
version: "rev-3"
---
```

When the version changes, OpenGraph+ re-renders even if the cache hasn't expired.

## Recommendations

| Page type | Strategy |
|-----------|----------|
| Static content pages | `og:plus:cache:max_age` of 604800 (1 week) |
| Blog posts | `og:plus:cache:max_age` of 86400 (1 day) + etag |
| Frequently updated | Short TTL + etag for instant invalidation |


## Troubleshooting

Sitepress runs on Rails, so most issues and solutions from the [Rails troubleshooting guide](/docs/rails/troubleshooting) apply directly.

## Meta tags not appearing

Check that the meta tags are in your layout's `<head>`. View the page source (not browser DevTools) to confirm the tags are present in the raw HTML.

Make sure you're editing the correct layout file. Sitepress pages can specify a different layout in their frontmatter.

## Wrong variables

Use `current_page.data.title` for frontmatter values and `current_page.request_path` for the page path. These are Sitepress-specific helpers.

## Wrong image showing

Social platforms and OpenGraph+ cache images. If you've updated your page but see the old image:

1. Purge the cached image from the OpenGraph+ dashboard
2. Wait a few minutes for the new image to render
3. Clear the platform's cache using their debugger tools (see below)

## Social platforms not updating

Social networks cache images aggressively. After purging from OpenGraph+, use each platform's debugger to force a refresh:

- **Facebook**: [Sharing Debugger](https://developers.facebook.com/tools/debug/)
- **Twitter/X**: [Card Validator](https://cards-dev.twitter.com/validator)
- **LinkedIn**: [Post Inspector](https://www.linkedin.com/post-inspector/)

## Purging cached images

1. Go to your OpenGraph+ dashboard
2. Navigate to the website's cache page
3. Enter the URL and purge

The next request from a social platform will trigger a fresh render.

## Testing

Use the preview tool in your OpenGraph+ dashboard to verify your setup before sharing URLs. This shows you exactly what social platforms will see.

