Skip to content

repo sync #2792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .yarn/install-state.gz
Binary file not shown.
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ plugins:
- jekyll-last-modified-at
- jekyll-dotenv
algolia:
max_record_size: 20000
application_id: UINQ2M4D9S
index_name: segment-docs
files_to_exclude:
Expand All @@ -72,4 +73,5 @@ algolia:
- searchable(hidden)
- searchable(tags)
- searchable(title)
- searchable(engage)
- type
92 changes: 90 additions & 2 deletions js/algolia/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ const apiKey = envApiKey != null ? envApiKey : sampleApiKey;
const placeHolder = envApiKey != null ? 'Search the Segment documentation' : 'Search disabled locally'

const searchClient = algoliasearch(appId, apiKey);
const loc = window.location.pathname

//insights
insightsClient('init', { appId, apiKey, useCookie: true });
const algoliaInsightsPlugin = createAlgoliaInsightsPlugin({ insightsClient });

// define locations to separate invocation for mobile and desktop
const locations = ['#autocomplete','#autocomplete-mobile'];
const engage_locations = ['#engage-autocomplete']

function initAutocomplete(item){
const search = autocomplete({
Expand Down Expand Up @@ -54,7 +56,7 @@ function initAutocomplete(item){
query,
params: {
hitsPerPage: 7,
facetFilters: ['hidden:-true', 'engage:-true'],
facetFilters: ['hidden:-true','engage:-true'],
clickAnalytics: true,
},
},
Expand Down Expand Up @@ -104,4 +106,90 @@ function initAutocomplete(item){

}

locations.forEach(initAutocomplete);
function initEngageAutocomplete(item){
const search = autocomplete({
container: item,
placeholder: "Search the Twilio Engage documentation",
debug: false,
openOnFocus: false,
keyboardShortcuts: ['s', 191],
plugins: [algoliaInsightsPlugin,],
detachedMediaQuery:'none',
getSources( {query} ) {
return [
{
sourceId: 'articles',
getItemUrl({ item }){
if (item.anchor != null) {
var itemUrl = '/docs'+item.url+"#" + item.anchor;
} else {
var itemUrl = '/docs'+item.url;
}
return itemUrl;
},
getItems() {
return getAlgoliaResults({
searchClient,
queries: [
{
indexName: 'segment-docs',
query,
params: {
hitsPerPage: 7,
facetFilters: ['hidden:-true'],
clickAnalytics: true,
},
},
],
});
},
templates: {
item({ item, createElement }){
if (item.anchor != null) {
var anchorLink = "#" + item.anchor;
} else {
var anchorLink = "";
}

if (item.engage){
var engage = "<span class='engage-pill'>Engage</span>"
}
return createElement('div',{
dangerouslySetInnerHTML: {
__html: `<a class="aa-link" href="/docs${item.url}${anchorLink}">
<p class="aa-title" >${highlightHit({hit: item, attribute: 'title'})} ${engage}</h3>
<p class="aa-content">${highlightHit({hit: item, attribute: 'content'})}</p></a>`
}
})
},
noResults() {
return html `<p class="aa-content">No results for <strong>${query}</strong></p>`;
}
},

},
];
},
navigator: {
navigate({ itemUrl }) {
window.location.assign(itemUrl);
},
navigateNewTab({ itemUrl }) {
const windowReference = window.open(itemUrl, '_blank', 'noopener');

if (windowReference) {
windowReference.focus();
}
},
navigateNewWindow({ itemUrl }) {
window.open(itemUrl, '_blank', 'noopener');
},
},
});

}
if (loc.startsWith("/docs/engage")) {
engage_locations.forEach(initEngageAutocomplete)
} else {
locations.forEach(initAutocomplete);
}
4 changes: 2 additions & 2 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
ignore = "./scripts/ignore.sh"

[context.branch-deploy]
command = "yarn develop"
ignore = "./scripts/ignore.sh"
command = "jekyll algolia && yarn build"
# ignore = "./scripts/ignore.sh"

[context.develop]
command = "yarn develop"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"browser-sync": "^2.27.7",
"check-links": "^1.1.8",
"clipboard": "^2.0.8",
"diff": "^5.0.0",
"dotenv": "^10.0.0",
"enquirer": "^2.3.6",
"fast-csv": "^4.3.6",
Expand Down
48 changes: 48 additions & 0 deletions scripts/engage-compare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const path = require('path');
const fs = require('fs');
const fm = require('front-matter');
const yaml = require('js-yaml');
const Diff = require('diff')
const ora = require('ora')
const {
type
} = require('os');
const pages = yaml.load(fs.readFileSync(path.resolve(__dirname, `../src/_data/engage-compare.yml`)))


const compare = async () => {
let title = ""
let engage_path = ""
let personas_path = ""


for (const key in pages) {
title = pages[key].title
engage_path = pages[key].engage
personas_path = pages[key].personas
const throbber = ora(`${title}`).start()

const engage_article = path.resolve(engage_path)
const personas_article = path.resolve(personas_path)

try {
const e = fm(fs.readFileSync(engage_article, 'utf8')).body;
const p = fm(fs.readFileSync(personas_article, 'utf8')).body;
const diff = Diff.diffChars(p, e)

if (diff.length > 1) {
throbber.fail(`${title} has diffs!`)
} else {
throbber.succeed()
}


} catch (e) {
console.log(e)
return false
}

}
}

compare()
Loading