WebSphere Portal 中的 SEO(页面标题)

发布于 2024-11-04 18:20:52 字数 3424 浏览 0 评论 0原文

页面标题

有没有办法在运行时动态更改页面标题?

我知道您可以在门户级别更改页面标题,但是这个解决方案 不提供任何 SEO 价值,因为它不会更改页面中的 TITLE 标记。

据我所知,更改门户标题的方式非常静态(这些是全局设置):

  • 更改主题策略中的bannerTitleText
  • 如果不存在,请将bannerTitleTextResourceBundle 和bannerTitleTextResourceKey 调整为所需的值。
  • 否则,在主题配置中全局设置标题

我们的目标是能够在页面级别设置标题,以便它可以在不同页面之间进行更改并包含相关页面的关键字。

实际上,如果这可以从 WCM 完成,那将是最理想的。

更新

我注意到 WebSphere Portal 6.1.5 中的默认主题是附加页面标题,因此检查了主题,当然 jspInit.jspf 有以下一些新方法:



private static com.ibm.portal.state.service.PortalStateManagerServiceHome portalStateManagerServiceHome;

// (This goes in the jspInit constructor)
portalStateManagerServiceHome = (com.ibm.portal.state.service.PortalStateManagerServiceHome) ctx.lookup("portal:service/state/PortalStateManager");

protected com.ibm.portal.state.service.PortalStateManagerService getStateManagerService( javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws Exception {
    final com.ibm.portal.state.service.PortalStateManagerService psms = portalStateManagerServiceHome.getPortalStateManagerService( (javax.servlet.http.HttpServletRequest) request, (javax.servlet.http.HttpServletResponse) response );
    return psms;
}
protected boolean isStaticPage( javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
    final com.ibm.portal.model.NavigationSelectionModelProvider nsmProvider = navigationSelectionModelHome.getNavigationSelectionModelProvider();
    final com.ibm.portal.navigation.NavigationSelectionModel nsm = nsmProvider.getNavigationSelectionModel(request, response);
    final com.ibm.portal.navigation.NavigationNode currentNavNode = (com.ibm.portal.navigation.NavigationNode) nsm.getSelectedNode();
    final com.ibm.portal.content.ContentNode currentContentNode = currentNavNode.getContentNode();

    return currentContentNode.getContentNodeType().equals( com.ibm.portal.content.ContentNodeType.STATICPAGE );
}

protected com.ibm.portal.navigation.NavigationNode getSelectedNode( final javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
    com.ibm.portal.model.NavigationSelectionModelProvider nsmProvider = navigationSelectionModelHome.getNavigationSelectionModelProvider();
    com.ibm.portal.navigation.NavigationSelectionModel nsm = nsmProvider.getNavigationSelectionModel(request, response);
    return (com.ibm.portal.navigation.NavigationNode) nsm.getSelectedNode();
}

protected String getSelectedNodeTitle( final javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
    final String title;
    if ( localizedContextHome != null ) {
        com.ibm.portal.model.LocalizedContext context = localizedContextHome.getLocalizedContext( (javax.servlet.http.HttpServletRequest) request );
        title = context.getTitle( getSelectedNode( request, response ) );
    } else {
        title = "";
    }

    return title;
}

添加此方法后,我能够从 6.1.5 主题复制 head_title.jspf ;其中包括以下新行:


<c:set var="selectedNodeTitle" value="<%=getSelectedNodeTitle(request, response)%>" />
<title><c:out value="${siteTitle} - ${selectedNodeTitle}"/></title>

现在剩下的就是找出一种从 WCM 获取此内容的方法。

Page Title

Is there a way to dinamically change the pages title at runtime?

I know that you can change the page title at the portal level, but this solution
doesn't offer any SEO value since it doesn't change the TITLE tag in the page.

For what I've seen the way to changing the portal titles are very static (these are global settings):

  • Changing the bannerTitleText in the theme policy
  • If that's not present adjust the bannerTitleTextResourceBundle and bannerTitleTextResourceKey to the desired value.
  • Otherwise, set the titles globally at the theme configuration

Our goal is to be able to set the title at the page level so that it can change from page to page and include the relevant page's keyword.

Actually it would be most ideal if this could be done from WCM.

Update

I noticed that the default theme in WebSphere Portal 6.1.5 was appending the page title, so examined the theme and surely enough the jspInit.jspf had some the following new methods:



private static com.ibm.portal.state.service.PortalStateManagerServiceHome portalStateManagerServiceHome;

// (This goes in the jspInit constructor)
portalStateManagerServiceHome = (com.ibm.portal.state.service.PortalStateManagerServiceHome) ctx.lookup("portal:service/state/PortalStateManager");

protected com.ibm.portal.state.service.PortalStateManagerService getStateManagerService( javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws Exception {
    final com.ibm.portal.state.service.PortalStateManagerService psms = portalStateManagerServiceHome.getPortalStateManagerService( (javax.servlet.http.HttpServletRequest) request, (javax.servlet.http.HttpServletResponse) response );
    return psms;
}
protected boolean isStaticPage( javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
    final com.ibm.portal.model.NavigationSelectionModelProvider nsmProvider = navigationSelectionModelHome.getNavigationSelectionModelProvider();
    final com.ibm.portal.navigation.NavigationSelectionModel nsm = nsmProvider.getNavigationSelectionModel(request, response);
    final com.ibm.portal.navigation.NavigationNode currentNavNode = (com.ibm.portal.navigation.NavigationNode) nsm.getSelectedNode();
    final com.ibm.portal.content.ContentNode currentContentNode = currentNavNode.getContentNode();

    return currentContentNode.getContentNodeType().equals( com.ibm.portal.content.ContentNodeType.STATICPAGE );
}

protected com.ibm.portal.navigation.NavigationNode getSelectedNode( final javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
    com.ibm.portal.model.NavigationSelectionModelProvider nsmProvider = navigationSelectionModelHome.getNavigationSelectionModelProvider();
    com.ibm.portal.navigation.NavigationSelectionModel nsm = nsmProvider.getNavigationSelectionModel(request, response);
    return (com.ibm.portal.navigation.NavigationNode) nsm.getSelectedNode();
}

protected String getSelectedNodeTitle( final javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
    final String title;
    if ( localizedContextHome != null ) {
        com.ibm.portal.model.LocalizedContext context = localizedContextHome.getLocalizedContext( (javax.servlet.http.HttpServletRequest) request );
        title = context.getTitle( getSelectedNode( request, response ) );
    } else {
        title = "";
    }

    return title;
}

After adding this I was able to copy the head_title.jspf from the 6.1.5 theme; which includes the following new lines:


<c:set var="selectedNodeTitle" value="<%=getSelectedNodeTitle(request, response)%>" />
<title><c:out value="${siteTitle} - ${selectedNodeTitle}"/></title>

Now all that's left is figuring out a way of fetching this from WCM.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狼性发作 2024-11-11 18:20:52

我将介绍缺少的 WCM 部分,因为我已经实现了该部分。我将能够为您提供所需的信息,但没有现成的代码。它只是从一个流中读取并写入另一个流,所以你应该能够理解这个想法。使用 Portal 6.1 最合理的方法是为此开发一个 Servlet Filter要求。您想要做的是:

  1. 使 WCM 组件打印出您想要注入 html 标头的正确信息。这最典型地意味着例如导航器组件打印当前路径/标题。
  2. 将这些组件添加到您的演示模板中。你想要的可能是使用 html 注释标签 以及一些稍后可以从生成的 html 中解析的方案。
  3. 构建一个 Servlet 过滤器,如果是 html/xhtml(使用 mime 类型),则从 ServletResponse 读取整个页面。当你这样做的时候,把评论解析掉。现在,在 html 标头部分中使用正确的标签重写一个新页面。
  4. 重新注入新的响应页面,这次具有正确的 SEO html 标头。

不幸的是,这是你必须采取的方式。甚至没有隐藏/私有 API 允许您从 WCM 呈现 portlet 的应用程序上下文中获取所需内容并将其放入 html 标头中。此外,您还必须将 servlet 过滤器添加到 wps 应用程序中。这里的一个常见问题是您必须在编辑 web.xml 后重新部署它。

servlet 过滤器对性能的影响可以忽略不计(总共只占几个百分比),而且该方法很有效。根据我的经验,它对于 SEO 目的非常有效,您几乎可以通过这种方式从 WCM 获取任何信息。

I will cover the missing WCM part, since I have implemented that. I will be able to give you required information but not ready code. It is just reading from a stream and writing into an other anyways so you should be able to grasp the idea. The most reasonable way using Portal 6.1 is to develop a Servlet Filter for this requirement. What you want to do is:

  1. Make WCM components that print out the correct information you want to inject to the html headers. This most typically means for instance navigator component to print the current path / title.
  2. Add those components to your presentation templates. What you want it probably to use html comment tags <!-- --> and some scheme you can parse later on from the generated html.
  3. Build a servlet filter that reads the whole page from the ServletResponse if it is html/xhtml (use the mime type). Parse the comments away while you do that. Now, rewrite a new page with correct tags in the html header section.
  4. Re-inject the new response page which this time has correct html headers for SEO.

Unfortunately this is the way you have to take. There aren't even hidden/private APIs that would allow you to take what you want from the WCM rendering portlets' application context and put it into the html headers. Also, you have to add the servlet filter to the wps application. A common gotcha here is that you have to re-deploy it after you edit the web.xml.

The performance impact of the servlet filter is negligible (only couple percentages in total), and the approach simply works. In my experience it works very well for SEO purposes, and you can get practically any information from WCM this way.

对岸观火 2024-11-11 18:20:52

我只是想更新这个问题,以提及有一个新功能可以提供更好的方法来实现相同的目标。

新的 Web 内容查看器 (286) 利用 JSR 286 中称为两阶段呈现的新功能,其中创建了一个称为 doHeaders 的新事件。在 doHeaders 事件下,可以修改响应以在头部添加元素,例如标题。

现在,Web 内容查看器提供了页面显示标题设置,使您能够从内容中选择

现在剩下的就是让我们开发人员能够从 Web 内容中设置其他元素,例如:规范元素/链接、元标记等。但我认为新的 Web 内容文件夹功能可以使我们能够在主题级别构建某些内容。

祝每一位具有 SEO 意识的 Lotus Web Content Management 开发人员好运。

I just wanted to update this question to mention that there's a new feature that enables a better way to achieve this same goal.

The new Web Content Viewer (286) takes advantage of a new feature in the JSR 286 called two phase rendering in which a new event is created called doHeaders. Under the doHeaders event the response can be modified in order to add elements in the head such as title.

Now the Web Content Viewer provides a Page Display Title setting which enables you to do a Select from content.

Now all that's left really is to enable us developers set other elements from Web Content such as: Canonical elements/links, meta tags, etc. But I think that the new Web Content Folders feature can enable us to build something at the theme level.

Good luck to every SEO conscious Lotus Web Content Management developers out there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文