SassDoc / sassdoc-theme-default

Default theme for SassDoc.
MIT License
10 stars 30 forks source link

Search suggestions hrefs are no longer valid #86

Closed ricardocasares closed 8 years ago

ricardocasares commented 8 years ago

Since PR #84 modified the markup of each section to include the group in the id attribute, this change breaks the search suggestions feature, since generated anchors are no longer valid.

One way to solve this could be to modify this file:

  Search.prototype.initialize = function () {
    // Fuse engine instanciation
    this.index = new Fuse($.map($(this.conf.search.items), function (item) {
      var $item = $(item);

      return {
        group: $item.data('group'), // <=== To include group
        name: $item.data('name'),
        type: $item.data('type'),
        node: $item
      };
    }), this.conf.fuse);

    this.initializeSearch();
  };

And here:

  Search.prototype.fillSuggestions = function (items) {
    var searchSuggestions = $(this.conf.search.suggestionsWrapper);
    searchSuggestions.html('');

    var suggestions = $.map(items.slice(0, 10), function (item) {
      var $li = $('<li />', {
        'data-group': item.group,
        'data-type': item.type,
        'data-name': item.name,
        'html': '<a href="#' + item.group + '-' + item.type + '-' + item.name + '"><code>' + item.type.slice(0, 3) + '</code> ' + item.name + '</a>'
      });

      searchSuggestions.append($li);
      return $li;
    });

    return suggestions;
  };

And add this new data-group attribute to each .sassdoc__item here:

<li class="sidebar__item  sassdoc__item" data-group="{{ group_name }}" data-name="{{ item.context.name }}" data-type="{{ item.context.type }}">
KittyGiraudel commented 8 years ago

Hey. Nice catch, we are sorry about this… Do you feel like submitting a pull request maybe? :)

ricardocasares commented 8 years ago

Actually I'm not really sure this is the problem. Checking...

@update checked and opened PR