Skip to content

Commit

Permalink
Add title & description meta tags for portals
Browse files Browse the repository at this point in the history
- Also add "description" to AppModel
- Use the appModel's description for the default description meta tag

Issue #2150
  • Loading branch information
robyngit committed Jun 29, 2023
1 parent 5840e42 commit de3e8fc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
25 changes: 24 additions & 1 deletion src/js/models/AppModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ define(['jquery', 'underscore', 'backbone'],
*/
title: MetacatUI.themeTitle || "Metacat Data Catalog",

/**
* The default page description.
* @type {string}
* @since x.x.x
*/
description: "A research data catalog and repository that provides access to scientific data, metadata, and more.",

/**
* The name of this repository. This is used throughout the interface in different
* messages and page content.
Expand Down Expand Up @@ -2373,7 +2380,23 @@ define(['jquery', 'underscore', 'backbone'],
'. Error details: ' + error
);
}
}
},

/**
* Reset the web document's title to the default
* @since x.x.x
*/
resetTitle: function () {
this.set("title", this.defaults.title);
},

/**
* Reset the web document's description to the default
* @since x.x.x
*/
resetDescription: function () {
this.set("description", this.defaults.description);
},

});
return AppModel;
Expand Down
2 changes: 1 addition & 1 deletion src/js/templates/appHead.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<title><%=MetacatUI.appModel.get("repositoryName")%></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<meta name="description" content="Metacat UI">
<meta name="description" content="<%= MetacatUI.appModel.get('description') || MetacatUI %>">
<meta name="author" content="NCEAS Ecoinformatics Development Team">

<!-- Stylesheets -->
Expand Down
2 changes: 1 addition & 1 deletion src/js/themes/dataone/templates/appHead.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
 <title><%=MetacatUI.appModel.get("repositoryName")%></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<meta name="description" content="Metacat UI">
<meta name="description" content="<%= MetacatUI.appModel.get('description') || MetacatUI %>">
<meta name="author" content="Ecoinformatics Development Team">

<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
Expand Down
16 changes: 15 additions & 1 deletion src/js/views/AppView.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ define([

//Change the document title when the app changes the MetacatUI.appModel title at any time
this.listenTo(MetacatUI.appModel, "change:title", this.changeTitle);
this.listenTo(MetacatUI.appModel, "change:description", this.changeDescription);

this.checkIncompatibility();
},
Expand All @@ -103,11 +104,24 @@ define([
return this.el.querySelector(this.contentSelector);
},

//Changes the web document's title
/**
* Change the web document's title
*/
changeTitle: function () {
document.title = MetacatUI.appModel.get("title");
},

/**
* Change the web document's description
* @since x.x.x
*/
changeDescription: function () {
$("meta[name=description]").attr(
"content",
MetacatUI.appModel.get("description")
);
},

/** Render the main view and/or re-render subviews. Delegate rendering
and event handling to sub views.
---
Expand Down
2 changes: 1 addition & 1 deletion src/js/views/MetadataView.js
Original file line number Diff line number Diff line change
Expand Up @@ -2517,7 +2517,7 @@ define(['jquery',
this.$loading = null;

//Put the document title back to the default
MetacatUI.appModel.set("title", MetacatUI.appModel.defaults.title);
MetacatUI.appModel.resetTitle();

//Remove view-specific classes
this.$el.removeClass("container no-stylesheet");
Expand Down
11 changes: 10 additions & 1 deletion src/js/views/portals/PortalView.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ define(["jquery",
// create a portal model for repository
this.model = new Portal({
seriesId: this.portalId,
label: view.label
label: view.label,
name: this.nodeInfo.name,
description: this.nodeInfo.description,
});

// remove the members section directly from the model
Expand All @@ -287,6 +289,10 @@ define(["jquery",
*/
renderPortal: function () {

// Set the document title to the portal name
MetacatUI.appModel.set("title", this.model.get("name"))
MetacatUI.appModel.set("description", this.model.get("description"))

// Getting the correct portal label and seriesID
this.label = this.model.get("label");
this.portalId = this.model.get("seriesId");
Expand Down Expand Up @@ -1051,6 +1057,9 @@ define(["jquery",
* Any clean-up or housekeeping happens at this time.
*/
onClose: function () {

MetacatUI.appModel.resetTitle();
MetacatUI.appModel.resetDescription();
//Remove each subview from the DOM and remove listeners
_.invoke(this.subviews, "remove");

Expand Down

0 comments on commit de3e8fc

Please sign in to comment.