diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2008-12-31 19:29:50 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2008-12-31 19:29:50 +0100 |
| commit | dc66e451a966e5ab320451c87ad912a741a71d4e (patch) | |
| tree | d6e002d12d895517481612b699e5eaecb39e4258 | |
| parent | e57e8ac7b198cd02331f0b66c12c9166641d373b (diff) | |
| download | cataract-dc66e451a966e5ab320451c87ad912a741a71d4e.tar.xz | |
Use image title as meta description
Allow per-album meta tags
| -rw-r--r-- | generators.c | 34 | ||||
| -rw-r--r-- | items.c | 9 | ||||
| -rw-r--r-- | items.h | 3 | ||||
| -rw-r--r-- | sample/src/CIAF_1/index.xml | 9 | ||||
| -rw-r--r-- | sample/src/setup.xml | 9 | ||||
| -rw-r--r-- | setup.c | 4 | ||||
| -rw-r--r-- | setup.h | 1 |
7 files changed, 56 insertions, 13 deletions
diff --git a/generators.c b/generators.c index d26e4e7..6bcf637 100644 --- a/generators.c +++ b/generators.c @@ -374,18 +374,21 @@ write_html_album (TGallerySetup *setup, } if (strstr (b, "<!-- $(CGG_META_TAGS) -->")) { s1 = g_strdup_printf ("\t<meta name=\"generator\" content=\"Cataract Gallery Generator v%s\" />\n", APP_VERSION); - if (setup->meta_author) { - s2 = g_strdup_printf ("%s\t<meta name=\"author\" content=\"%s\" />\n", s1, setup->meta_author); + if (setup->meta_author || items->meta_author) { + s2 = g_strdup_printf ("%s\t<meta name=\"author\" content=\"%s\" />\n", s1, + items->meta_author ? items->meta_author : setup->meta_author); g_free (s1); s1 = s2; } - if (setup->meta_description) { - s2 = g_strdup_printf ("%s\t<meta name=\"description\" content=\"%s\" />\n", s1, setup->meta_description); + if (setup->meta_description || items->meta_description) { + s2 = g_strdup_printf ("%s\t<meta name=\"description\" content=\"%s\" />\n", s1, + items->meta_description? items->meta_description : setup->meta_description); g_free (s1); s1 = s2; } - if (setup->meta_keywords) { - s2 = g_strdup_printf ("%s\t<meta name=\"keywords\" content=\"%s\" />\n", s1, setup->meta_keywords); + if (setup->meta_keywords || items->meta_keywords) { + s2 = g_strdup_printf ("%s\t<meta name=\"keywords\" content=\"%s\" />\n", s1, + items->meta_keywords ? items->meta_keywords : setup->meta_keywords); g_free (s1); s1 = s2; } @@ -596,6 +599,7 @@ write_html_image (TGallerySetup *setup, char *b; gboolean res; int level; + gboolean override_title_meta; fin = fopen (template_src, "r"); @@ -893,19 +897,25 @@ write_html_image (TGallerySetup *setup, g_free (s1); } if (strstr (b, "<!-- $(CGG_META_TAGS) -->")) { + override_title_meta = setup->use_title_as_meta && title && (strlen (title) > 0); s1 = g_strdup_printf ("\t<meta name=\"generator\" content=\"Cataract Gallery Generator v%s\" />\n", APP_VERSION); - if (setup->meta_author) { - s2 = g_strdup_printf ("%s\t\t<meta name=\"author\" content=\"%s\" />\n", s1, setup->meta_author); + if (setup->meta_author || parent_items->meta_author) { + s2 = g_strdup_printf ("%s\t<meta name=\"author\" content=\"%s\" />\n", s1, + parent_items->meta_author ? parent_items->meta_author : setup->meta_author); g_free (s1); s1 = s2; } - if (setup->meta_description) { - s2 = g_strdup_printf ("%s\t<meta name=\"description\" content=\"%s\" />\n", s1, setup->meta_description); + if (setup->meta_description || parent_items->meta_description || override_title_meta) { + s3 = override_title_meta ? g_markup_escape_text (title, -1) : NULL; + s2 = g_strdup_printf ("%s\t<meta name=\"description\" content=\"%s\" />\n", s1, + override_title_meta ? s3 : (parent_items->meta_description ? parent_items->meta_description : setup->meta_description)); g_free (s1); + if (s3) g_free (s3); s1 = s2; } - if (setup->meta_keywords) { - s2 = g_strdup_printf ("%s\t<meta name=\"keywords\" content=\"%s\" />\n", s1, setup->meta_keywords); + if ((setup->meta_keywords || parent_items->meta_keywords) && (! override_title_meta)) { + s2 = g_strdup_printf ("%s\t<meta name=\"keywords\" content=\"%s\" />\n", s1, + parent_items->meta_keywords ? parent_items->meta_keywords : setup->meta_keywords); g_free (s1); s1 = s2; } @@ -83,6 +83,9 @@ parse_album_xml (const char *filename, TAlbum *index) index->portrait_height = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "portrait_h", 0); index->border_style = xml_file_get_node_attribute (xml, "/gallery/general/border", "style"); + index->meta_author = xml_file_get_node_value (xml, "/gallery/general/meta/author/text()"); + index->meta_description = xml_file_get_node_value (xml, "/gallery/general/meta/description/text()"); + index->meta_keywords = xml_file_get_node_value (xml, "/gallery/general/meta/keywords/text()"); /* Section Items */ count = xml_file_node_get_children_count (xml, "/gallery/items/*"); @@ -221,6 +224,12 @@ free_album_data (TAlbum *album) free (album->base_dir); if (album->border_style) free (album->border_style); + if (album->meta_author) + free (album->meta_author); + if (album->meta_description) + free (album->meta_description); + if (album->meta_keywords) + free (album->meta_keywords); if (album->items) { if (album->items->len > 0) { @@ -47,6 +47,9 @@ typedef struct { unsigned long portrait_width; unsigned long portrait_height; char *border_style; + char *meta_author; + char *meta_description; + char *meta_keywords; } TAlbum; typedef struct { diff --git a/sample/src/CIAF_1/index.xml b/sample/src/CIAF_1/index.xml index 7e89297..5d40936 100644 --- a/sample/src/CIAF_1/index.xml +++ b/sample/src/CIAF_1/index.xml @@ -18,6 +18,15 @@ <images quality="60" landscape_w="640" landscape_h="480" portrait_w="480" portrait_h="640" /> <!-- override global preview image border style --> <border style="border_none" /> + + <meta> + <!-- custom meta tags valid for this album page and all listed items --> + <!-- this will override global meta settings, however --> + <!-- the <use_title_as_meta> global setting has even higher priority --> + <author>John Doe Jr.</author> + <description>CIAF - Czech International Air Fest 2007</description> + <keywords>ciaf,aircraft,military,exhibition</keywords> + </meta> </general> <items> diff --git a/sample/src/setup.xml b/sample/src/setup.xml index ef37f9a..234e8f0 100644 --- a/sample/src/setup.xml +++ b/sample/src/setup.xml @@ -41,12 +41,19 @@ <erase_embed_thumbnail value="yes" /> </images> - <!-- META tags in html head section --> <meta> + <!-- global META tags in html head section --> + <!-- these will automatically apply to _all_ pages unless overriden in the album --> + <!-- it's not probably a good idea for large galleries --> <author>John Doe</author> <description>CGG Sample gallery</description> <!-- keywords are usually not needed at all --> <keywords>cataract, sample, gallery</keywords> + + <!-- use item (image) title as <meta description> tag value --> + <!-- (allowed values: "yes", "no") default = yes --> + <!-- this setting is independent from the global meta tags settings --> + <use_title_as_meta value="yes" /> </meta> <footer><