Ember app和google crawler

时间:2016-05-27 14:36:45

标签: javascript ajax ember.js web-crawler google-crawlers

我正在尝试使我的ember应用程序可以抓取。据我所知,谷歌现在支持JS,CSS和AJAX(从2015年10月开始)。但是当我通过“抓取为Google”测试我的网站时,我会得到一个带有背景的空白页面:https://gyazo.com/2b28487ac1a25e11e2e87888779e3f2a

实际上我的内容和页面看起来完全不同:https://gyazo.com/009a5a9719f80aef70fc22bc3d777cba

我做错了什么?

2 个答案:

答案 0 :(得分:1)

您可以使用Ember Fastboot - https://www.ember-fastboot.com/ 或使用http://www.emberjsseo.com/

等服务 祝你好运!

答案 1 :(得分:0)

经过一天的调查后,我发现了两个阻止爬行的问题。

1.输入验证组件。

import Ember from 'ember';

const {
  computed,
  observer,
  defineProperty,
  run
} = Ember;

export default Ember.Component.extend({
  classNames: ['form-group', 'has-feedback', 'validated-input'],
  classNameBindings: ['isValid:has-success', 'showErrorClass:has-error'],
  isValid: false,
  model: null,
  value: null,
  rawInputValue: null,
  type: 'text',
  valuePath: '',
  placeholder: '',
  attributeValidation: null,
  isTyping: false,

  didValidate: computed.oneWay('targetObject.didValidate'),

  showErrorClass: computed('isTyping', 'showMessage', 'hasContent', 'attributeValidation', function() {
    return this.get('attributeValidation') && !this.get('isTyping') && this.get('showMessage');
  }),

  hasContent: computed.notEmpty('rawInputValue'),

  isValid: computed.and('hasContent', 'attributeValidation.isValid'),

  isInvalid: computed.oneWay('attributeValidation.isInvalid'),

  inputValueChange: observer('rawInputValue', function() {
    this.set('isTyping', true);
    run.debounce(this, this.setValue, 500, false);
  }),

  showMessage: computed('attributeValidation.isDirty', 'isInvalid', 'didValidate', function() {
    return (this.get('attributeValidation.isDirty') || this.get('didValidate')) && this.get('isInvalid');
  }),

  setValue() {
    this.set('value', this.get('rawInputValue'));
    this.set('isTyping', false);
  },

  init() {
    this._super(...arguments);
    var valuePath = this.get('valuePath');
    defineProperty(this, 'attributeValidation', computed.oneWay(`model.validations.attrs.${valuePath}`));
    this.set('rawInputValue', this.get(`model.${valuePath}`));
    defineProperty(this, 'value', computed.alias(`model.${valuePath}`));
  }
});

我用更新的组件替换了这个组件。

2.这段代码(我为性能优化编写了代码):

ingredients: function() {
    var self = this;
    return DS.PromiseArray.create({
      promise: new Promise((resolve, reject) => {
        let loadedIngredients = self.store.peekAll('ingredient');
        if (loadedIngredients && loadedIngredients.get('length') > 0) {
          let mappedIngredients = self.get('recipe').get('ingredientsWithQuantities').map(function(item) {
            return {
              name: self.store.peekRecord('ingredient', item.ingredientId).get('name'),
              quantity: item.quantity
            };
          });
          resolve(mappedIngredients);
        } else {
          this.store.findAll('ingredient').then(function() {
            let mappedIngredients = self.get('recipe').get('ingredientsWithQuantities').map(function(item) {
              return {
                name: self.store.peekRecord('ingredient', item.ingredientId).get('name'),
                quantity: item.quantity
              };
            });
            resolve(mappedIngredients);
          })
        }
      })
    });
  }.property('recipe.ingredientsWithQuantities')

我修复了这两件事,现在谷歌机器人能够渲染我的应用程序。